Skip to content

refactor: clean up transaction model validations#2895

Open
mvadari wants to merge 76 commits intomainfrom
model-cleanup
Open

refactor: clean up transaction model validations#2895
mvadari wants to merge 76 commits intomainfrom
model-cleanup

Conversation

@mvadari
Copy link
Collaborator

@mvadari mvadari commented Feb 12, 2025

High Level Overview of Change

This PR cleans up the validation functions for transactions, to use newer helper functions. It also adds some helper functions for easier model validation test writing.

This process uncovered a few bugs, which are fixed.

The integration tests have not been touched at all, which shows that nothing major was changed.

Note for reviewers: the vast majority of the changes were made with regex find-and-replace, so while there are a lot of changes, most of them (especially in the test files) are pretty formulaic.

Context of Change

The validateRequiredField and validateOptionalField helper functions were added somewhat recently, and the older models don't use it.

Type of Change

  • Refactor (non-breaking change that only restructures code)

Did you update HISTORY.md?

  • Yes

Test Plan

Fixed tests. CI passes.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 12, 2025

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

This PR refactors transaction validation across the xrpl.js library by consolidating scattered validation logic into reusable helper functions (validateRequiredField, validateOptionalField) and introducing numerous type guards (isHexString, isArray, isNumberWithBounds, isCurrency, isXRPAmount, isMPTCurrency). The changes systematically replace manual type checks and error throwing with centralized validators, standardize error messages in test suites, and rename credential transaction files to lowercase for consistency.

Changes

Cohort / File(s) Summary
Core Validation Utilities
packages/xrpl/src/models/transactions/common.ts
Added new type guards (isArray, isHexString, isCurrencyString, isNumberWithBounds, isXRPAmount, isMPTCurrency); updated isCurrency to compose multiple guards; enhanced validateRequiredField and validateOptionalField signatures with optional invalidMessage parameter; updated validateBaseTransaction and credential validators; centralized error messaging via getErrorMessage and invalidMessagesMap.
AMM Transaction Validators
packages/xrpl/src/models/transactions/AMMBid.ts, AMMCreate.ts, AMMDelete.ts, AMMDeposit.ts, AMMVote.ts, AMMWithdraw.ts, AMMClawback.ts
Refactored validation to use validateRequiredField and validateOptionalField for Asset, Asset2, BidMin, BidMax, Amount, Amount2, TradingFee, EPrice, LPTokenOut, AuthAccounts; updated imports to use isCurrency instead of isIssuedCurrency; enhanced error reporting with array indices for nested validation.
Payment and Channel Transaction Validators
packages/xrpl/src/models/transactions/payment.ts, paymentChannelClaim.ts, paymentChannelCreate.ts, paymentChannelFund.ts
Replaced manual field validation with validateRequiredField and validateOptionalField for Amount, Channel, Balance, PublicKey, Signature, SettleDelay, Expiration; added isPaths validator for Path validation; updated imports to use isXRPAmount, isHexString; added DestinationTag property to PaymentChannelCreate.
Check Transaction Validators
packages/xrpl/src/models/transactions/checkCancel.ts, checkCash.ts, checkCreate.ts
Replaced manual checks for CheckID (now isHexString), Amount, DeliverMin, SendMax, Expiration, InvoiceID with reusable validators; removed direct ValidationError throws; uses validateRequiredField and validateOptionalField.
Escrow Transaction Validators
packages/xrpl/src/models/transactions/escrowCancel.ts, escrowCreate.ts, escrowFinish.ts
Refactored OfferSequence validation to use validateRequiredField with isNumber; replaced manual checks for CancelAfter, FinishAfter, Condition, Fulfillment with validateOptionalField using isHexString; removed direct ValidationError throws.
NFToken Transaction Validators
packages/xrpl/src/models/transactions/NFTokenAcceptOffer.ts, NFTokenCancelOffer.ts, NFTokenCreateOffer.ts, NFTokenMint.ts, NFTokenBurn.ts, NFTokenModify.ts
Updated NFTokenID and URI validation to use isHexString; replaced manual checks with validateRequiredField/validateOptionalField for NFTokenOffers, Amount, Expiration, NFTokenSellOffer, NFTokenBuyOffer, NFTokenBrokerFee; added MAX_TRANSFER_FEE constant; enhanced validation for optional fields.
Offer and Ticket Transaction Validators
packages/xrpl/src/models/transactions/offerCancel.ts, offerCreate.ts, ticketCreate.ts
Replaced manual OfferSequence validation with validateRequiredField using isNumber; updated TakerGets, TakerPays, Expiration validators; changed TicketCount to use isNumberWithBounds(1, 250).
DID and Credential Transaction Validators
packages/xrpl/src/models/transactions/credentialAccept.ts, credentialCreate.ts, credentialDelete.ts, DIDSet.ts, DIDDelete.ts
Updated Account, Subject, Issuer validation to use isAccount instead of isString; changed Data, DIDDocument, URI from isString to isHexString; removed direct ValidationError throws; added documentation comments.
XChain Transaction Validators
packages/xrpl/src/models/transactions/XChainAddAccountCreateAttestation.ts, XChainAddClaimAttestation.ts, XChainClaim.ts, XChainCommit.ts
Updated PublicKey, Signature to use isHexString; changed XChainClaimID and XChainAccountCreateCount validation to accept number or hex string with invalidMessage parameter; added explicit error messages for WasLockingChainSend.
Trust and Domain Transaction Validators
packages/xrpl/src/models/transactions/trustSet.ts, permissionedDomainDelete.ts, permissionedDomainSet.ts
Updated LimitAmount to use validateRequiredField with isIssuedCurrencyAmount; changed DomainID validation from isString to isHexString; replaced AcceptedCredentials array check with isArray.
Vault Transaction Validators
packages/xrpl/src/models/transactions/vaultClawback.ts, vaultCreate.ts, vaultDelete.ts, vaultDeposit.ts, vaultSet.ts, vaultWithdraw.ts
Updated VaultID validation to use isHexString; changed Data, MPTokenMetadata, DomainID from isString to isHexString; removed explicit hex validation checks; preserved byte length constraints.
Oracle and Set-like Transaction Validators
packages/xrpl/src/models/transactions/oracleSet.ts, accountSet.ts, setRegularKey.ts, signerListSet.ts, delegateSet.ts
Refactored Provider, URI, AssetClass to use isHexString; updated nested array validation for PriceDataSeries with index-based error context; changed RegularKey to use isAccount; updated WalletLocator and Permissions validation; added per-element validation for DelegateSet.Permissions.
Clawback and Batch Validators
packages/xrpl/src/models/transactions/clawback.ts, batch.ts
Updated Amount validation to use isClawbackAmount and refined error messages; changed RawTransactions validation error message to specify "valid Record"; refined control flow for issued currency and MPT cases.
MPToken Transaction Validators
packages/xrpl/src/models/transactions/MPTokenAuthorize.ts, MPTokenIssuanceCreate.ts, MPTokenIssuanceSet.ts, MPTokenIssuanceDestroy.ts
Updated MPTokenIssuanceID validation to use isHexString; changed Flags type from specific enum to Record<string, unknown>; enhanced flag evaluation with explicit boolean checks; changed MPTokenMetadata validation to isHexString with empty string check.
Transaction Index and Type Definitions
packages/xrpl/src/models/transactions/index.ts, transaction.ts, packages/xrpl/src/models/common/index.ts
Updated import paths for CredentialAccept, CredentialCreate, CredentialDelete from uppercase to lowercase filenames; added new public type XRPAmount; updated Amount type to use XRPAmount union.
Utility Functions
packages/xrpl/src/models/utils/index.ts, packages/xrpl/src/sugar/autofill.ts
Modified HEX_REGEX to allow zero or more hex characters; renamed isFlagEnabled parameter from Flags to flags; enhanced validateAccountAddress with explicit presence checks and local variable handling.
Serialization Updates
packages/ripple-binary-codec/src/types/st-array.ts
Added null check in isObjects function to prevent errors with null array elements.
Test Utilities and Assertion Helpers
packages/xrpl/test/testUtils.ts, packages/xrpl/tools/createValidateTests.js
Updated assertTxValidationError to accept `string
AMM and Core Transaction Tests
packages/xrpl/test/models/AMMBid.test.ts, AMMCreate.test.ts, AMMDelete.test.ts, AMMDeposit.test.ts, AMMVote.test.ts, AMMWithdraw.test.ts
Updated error messages to use standardized format: "invalid field X, expected a valid Y"; added assertValid and assertInvalid helper functions; refined test assertions for invalid field types.
NFToken Test Updates
packages/xrpl/test/models/NFTokenAcceptOffer.test.ts, NFTokenCreateOffer.test.ts, NFTokenMint.test.ts, NFTokenModify.test.ts, NFTokenBurn.test.ts
Updated error messages to specify expected types; replaced direct validation calls with assertValid/assertInvalid helpers; changed convertStringToHex to stringToHex in NFTokenMint tests.
Payment Channel and Check Test Updates
packages/xrpl/test/models/paymentChannelClaim.test.ts, paymentChannelCreate.test.ts, paymentChannelFund.test.ts, checkCancel.test.ts, checkCash.test.ts, checkCreate.test.ts
Standardized error messages to "invalid field X, expected a valid Y"; added assertValid/assertInvalid helpers; updated test value types (e.g., changed numeric strings to non-numeric for type validation).
Escrow and Offer Test Updates
packages/xrpl/test/models/escrowCancel.test.ts, escrowCreate.test.ts, escrowFinish.test.ts, offerCancel.test.ts, offerCreate.test.ts, ticketCreate.test.ts
Updated error messages with "invalid field" and "missing field" prefixes; refined expected types (e.g., "expected a valid hex string", "expected a valid number"); refactored assertions with new helper functions.
DID and Credential Test Updates
packages/xrpl/test/models/CredentialAccept.test.ts, CredentialCreate.test.ts, CredentialDelete.test.ts, DIDSet.test.ts, credentialDelete.test.ts
Updated import paths for lowercase filenames; refined error messages to specify expected types (e.g., "expected a valid account address", "expected a valid hex string"); removed generic "invalid field" messages.
XChain and Trust Test Updates
packages/xrpl/test/models/XChainAccountCreateCommit.test.ts, XChainAddAccountCreateAttestation.test.ts, XChainAddClaimAttestation.test.ts, XChainClaim.test.ts, XChainCommit.test.ts, XChainCreateBridge.test.ts, XChainCreateClaimID.test.ts, XChainModifyBridge.test.ts, trustSet.test.ts
Added detailed error messages specifying expected types; refactored test assertions with assertValid/assertInvalid; updated variable type annotations to any; refined validation error expectations for numeric and hex string fields.
Vault and Domain Test Updates
packages/xrpl/test/models/vaultClawback.test.ts, vaultCreate.test.ts, vaultDelete.test.ts, vaultDeposit.test.ts, vaultSet.test.ts, vaultWithdraw.test.ts, permissionedDomainDelete.test.ts, permissionedDomainSet.test.ts
Removed VaultX type imports; changed tx variable type to any; updated error messages to include expected formats (e.g., "expected a valid hex string"); removed @ts-expect-error comments; refined validation expectations.
Integration and Batch Tests
packages/xrpl/test/integration/transactions/credentialDelete.test.ts, permissionedDEX.test.ts, packages/xrpl/test/models/batch.test.ts, delegateSet.test.ts, baseTransaction.test.ts, accountDelete.test.ts, accountSet.test.ts
Updated import paths to lowercase; refined error messages for array validation and field type expectations; added test cases for flag objects; updated batch validation error messages; enhanced permission validation errors with array indices.
Oracle and Special Transaction Tests
packages/xrpl/test/models/oracleSet.test.ts, oracleDelete.test.ts, payment.test.ts, depositPreauth.test.ts, loanBrokerCoverDeposit.test.ts, loanBrokerCoverWithdraw.test.ts, AMMClawback.test.ts
Updated expected error messages with specific field types and formats; refined validation error assertions for complex nested fields; added more descriptive error messages for invalid array elements and indexed field paths.
Wallet and Settings Updates
packages/xrpl/test/wallet/index.test.ts, .vscode/settings.json
Updated error message patterns for BaseTransaction and NFTokenMint validation; changed spelling to lowercase "permissioned"; added spell-check entries for "nftoken" and "Trustlines".

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested reviewers

  • achowdhry-ripple
  • ckeshava
  • khancode

Poem

🐰 With whiskers twitching at this grand refactor, we hop through validation fields so neatly ordered! Each validateRequiredField and isHexString makes the code more structured—errors dance in messages clear, and tests are standardized throughout the year! Thump thump!

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title 'refactor: clean up transaction model validations' directly summarizes the main change—consolidating transaction validation code to use newer helper functions while improving code organization.
Description check ✅ Passed The PR description fully addresses the template requirements with a clear overview, context explaining the use of newer helper functions, proper type of change selection (Refactor), confirmation that HISTORY.md was updated, and a test plan confirming tests were fixed and CI passes.
Docstring Coverage ✅ Passed Docstring coverage is 92.59% which is sufficient. The required threshold is 80.00%.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch model-cleanup

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot]

This comment was marked as resolved.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 9

🔭 Outside diff range comments (5)
packages/xrpl/test/models/NFTokenCancelOffer.test.ts (2)

1-21: ⚠️ Potential issue

Add missing imports for test dependencies.

The test is using assert and validate but they are not imported. Add the following imports at the beginning of the file:

+import { assert } from 'chai'
+import { validate } from '../validate'
🧰 Tools
🪛 ESLint

[error] 1-48: This module could be parsed as a valid script.

(import/unambiguous)

🪛 GitHub Actions: Node.js CI

[error] 20-20: Cannot find name 'assert'.


[error] 20-20: Cannot find name 'validate'.


[error] 20-20: Cannot find name 'assert'.


[error] 20-20: Cannot find name 'validate'.


[error] 20-20: Cannot find name 'assert'.


[error] 20-20: Cannot find name 'validate'.


23-33: ⚠️ Potential issue

Add import for assertInvalid helper.

The test is using the new assertInvalid helper but it's not imported. Add the following import:

+import { assertInvalid } from '../testUtils'

The error message format aligns with the PR's objective of standardizing validation messages.

🧰 Tools
🪛 GitHub Actions: Node.js CI

[error] 32-32: Cannot find name 'assertInvalid'.


[error] 32-32: Cannot find name 'assertInvalid'.


[error] 32-32: Cannot find name 'assertInvalid'.

packages/xrpl/test/models/clawback.test.ts (1)

81-81: ⚠️ Potential issue

Fix async function call in MPT Clawback test.

Similar to the previous issue, this test case also needs to handle the async validation correctly.

Apply this diff to fix the async issues:

-    assert.doesNotThrow(() => validate(validClawback))
+    await assert.doesNotReject(async () => validate(validClawback))

Also update the test function to be async:

-  it(`verifies valid MPT Clawback`, function () {
+  it(`verifies valid MPT Clawback`, async function () {
🧰 Tools
🪛 GitHub Actions: Node.js CI

[error] 81-81: Functions that return promises must be async


[error] 81-81: Unsafe return of an any typed value

packages/xrpl/test/models/MPTokenIssuanceDestroy.test.ts (1)

1-2: ⚠️ Potential issue

Add missing imports to fix pipeline failures.

The file is using undefined functions that need to be imported.

Add the following imports at the beginning of the file:

+import { validate } from '../../src/models'
+import { validateMPTokenIssuanceDestroy } from '../../src/models/transactions/MPTokenIssuanceDestroy'
+import { assertTxIsValid, assertTxValidationError } from '../testUtils'

 const TOKEN_ID = '000004C463C52827307480341125DA0577DEFC38405B0E3E'

Also, define the utility functions:

+const assertValid = (tx: any): void =>
+  assertTxIsValid(tx, validateMPTokenIssuanceDestroy)
+const assertInvalid = (tx: any, message: string): void =>
+  assertTxValidationError(tx, validateMPTokenIssuanceDestroy, message)
🧰 Tools
🪛 ESLint

[error] 1-31: This module could be parsed as a valid script.

(import/unambiguous)

packages/xrpl/test/models/NFTokenBurn.test.ts (1)

1-3: ⚠️ Potential issue

Add missing imports to fix pipeline failures.

The file is using undefined functions that need to be imported.

Add the following imports and utility functions:

+import { validate } from '../../src/models'
+import { validateNFTokenBurn } from '../../src/models/transactions/NFTokenBurn'
+import { assertTxIsValid, assertTxValidationError } from '../testUtils'

 const TOKEN_ID =
   '00090032B5F762798A53D543A014CAF8B297CFF8F2F937E844B17C9E00000003'

+const assertValid = (tx: any): void =>
+  assertTxIsValid(tx, validateNFTokenBurn)
+const assertInvalid = (tx: any, message: string): void =>
+  assertTxValidationError(tx, validateNFTokenBurn, message)
🧰 Tools
🪛 ESLint

[error] 1-35: This module could be parsed as a valid script.

(import/unambiguous)

🧹 Nitpick comments (37)
packages/xrpl/test/models/AMMWithdraw.test.ts (1)

88-152: Consider using undefined assignment instead of delete operator.

While the validation refactoring looks good, the use of delete operator in test cases could impact performance.

Apply this diff to improve performance:

-    delete withdraw.Asset
+    withdraw.Asset = undefined
-    delete withdraw.Asset2
+    withdraw.Asset2 = undefined
🧰 Tools
🪛 Biome (1.9.4)

[error] 89-89: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 101-101: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/AMMVote.test.ts (2)

14-14: Consider using a more specific type instead of any.

Using any type bypasses TypeScript's type checking. Consider defining an interface for the AMMVote transaction type to improve type safety.

interface AMMVoteTransaction {
  TransactionType: 'AMMVote'
  Account: string
  Asset: {
    currency: string
  }
  Asset2: {
    currency: string
    issuer: string
  }
  TradingFee: number
  Sequence: number
}

37-37: Consider using undefined assignment instead of delete operator.

For better performance, consider replacing delete operations with undefined assignments:

-delete vote.Asset
+vote.Asset = undefined

-delete vote.Asset2
+vote.Asset2 = undefined

-delete vote.TradingFee
+vote.TradingFee = undefined

Also applies to: 49-49, 61-61

🧰 Tools
🪛 Biome (1.9.4)

[error] 37-37: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/oracleDelete.test.ts (1)

29-29: Consider avoiding the delete operator.

Using the delete operator can impact performance. Consider using an undefined assignment instead.

-    delete tx.OracleDocumentID
+    tx.OracleDocumentID = undefined
🧰 Tools
🪛 Biome (1.9.4)

[error] 29-29: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/XChainAccountCreateCommit.test.ts (3)

4-7: Consider using proper types instead of any.

The helper functions could benefit from proper type definitions to maintain type safety. Consider using the transaction type from the validation function.

-const assertValid = (tx: any): void =>
+const assertValid = (tx: XChainAccountCreateCommit): void =>
   assertTxIsValid(tx, validateXChainAccountCreateCommit)
-const assertInvalid = (tx: any, message: string): void =>
+const assertInvalid = (tx: Partial<XChainAccountCreateCommit>, message: string): void =>
   assertTxValidationError(tx, validateXChainAccountCreateCommit, message)

15-15: Consider using proper type instead of any.

For better type safety and IDE support, consider using the proper transaction type.

-let tx: any
+let tx: XChainAccountCreateCommit

45-45: Consider alternatives to the delete operator.

The delete operator can impact performance. Consider using undefined assignment instead.

-delete tx.XChainBridge
+tx.XChainBridge = undefined

-delete tx.SignatureReward
+tx.SignatureReward = undefined

-delete tx.Destination
+tx.Destination = undefined

-delete tx.Amount
+tx.Amount = undefined

Also applies to: 57-57, 75-75, 87-87

🧰 Tools
🪛 Biome (1.9.4)

[error] 45-45: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/AMMDeposit.test.ts (3)

7-9: Consider using more specific types instead of any.

While any works, using more specific types would improve type safety and maintainability. Consider creating an interface for the transaction type.

-const assertValid = (tx: any): void => assertTxIsValid(tx, validateAMMDeposit)
-const assertInvalid = (tx: any, message: string): void =>
+interface AMMDepositTransaction {
+  TransactionType: 'AMMDeposit'
+  Account: string
+  Asset: any  // Replace with specific type
+  Asset2: any // Replace with specific type
+  [key: string]: any
+}
+const assertValid = (tx: AMMDepositTransaction): void => assertTxIsValid(tx, validateAMMDeposit)
+const assertInvalid = (tx: Partial<AMMDepositTransaction>, message: string): void =>

22-22: Consider using the specific transaction type instead of any.

Replace any with the suggested AMMDepositTransaction type to improve type safety.

-let deposit: any
+let deposit: AMMDepositTransaction

77-93: Consider using undefined assignment instead of delete operator.

The delete operator can impact performance. Consider using undefined assignment instead.

-delete deposit.Asset
+deposit.Asset = undefined
🧰 Tools
🪛 Biome (1.9.4)

[error] 78-78: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 90-90: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/escrowCreate.test.ts (2)

14-14: Consider using proper transaction type instead of any.

Replace any with the proper transaction type to improve type safety and catch potential issues at compile time.

-  let escrow: any
+  let escrow: EscrowCreate

36-36: Consider using undefined assignment instead of delete operator.

The delete operator can impact performance. Consider using undefined assignment instead:

-    delete escrow.Amount
+    escrow.Amount = undefined

-    delete escrow.Destination
+    escrow.Destination = undefined

-    delete escrow.CancelAfter
-    delete escrow.FinishAfter
+    escrow.CancelAfter = undefined
+    escrow.FinishAfter = undefined

-    delete escrow.Condition
-    delete escrow.FinishAfter
+    escrow.Condition = undefined
+    escrow.FinishAfter = undefined

Also applies to: 42-42, 84-85, 94-95

🧰 Tools
🪛 Biome (1.9.4)

[error] 36-36: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/paymentChannelClaim.test.ts (2)

4-7: Consider using a more specific type instead of any.

While any works, using a more specific type would improve type safety. Consider creating an interface or type that represents the expected transaction structure.

-const assertValid = (tx: any): void =>
+interface PaymentChannelClaimTx {
+  Account?: string
+  TransactionType: 'PaymentChannelClaim'
+  Channel?: string
+  Balance?: string
+  Amount?: string
+  Signature?: string
+  PublicKey?: string
+}
+const assertValid = (tx: PaymentChannelClaimTx): void =>
   assertTxIsValid(tx, validatePaymentChannelClaim)
-const assertInvalid = (tx: any, message: string): void =>
+const assertInvalid = (tx: PaymentChannelClaimTx, message: string): void =>
   assertTxValidationError(tx, validatePaymentChannelClaim, message)

15-15: Use the specific transaction type for better type safety.

Replace any with the specific transaction type to improve type safety and code maintainability.

-  let channel: any
+  let channel: PaymentChannelClaimTx
packages/xrpl/test/models/offerCancel.test.ts (1)

47-48: Consider alternative to delete operator.

While the error message update follows the new consistent format, static analysis flags the use of the delete operator due to potential performance impact.

Although the performance impact is negligible in test context, you could consider using undefined assignment instead:

-delete offer.OfferSequence
+offer.OfferSequence = undefined

However, using delete more clearly expresses the intent to test a missing field. The choice is yours based on whether you prioritize performance or clarity in tests.

🧰 Tools
🪛 Biome (1.9.4)

[error] 47-47: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/paymentChannelCreate.test.ts (2)

4-7: Consider using a more specific type for the tx parameter.

Instead of using any, consider creating an interface or type that represents the expected shape of a PaymentChannelCreate transaction. This would provide better type safety and documentation.

-const assertValid = (tx: any): void =>
+interface PaymentChannelCreateTransaction {
+  Account: string
+  TransactionType: 'PaymentChannelCreate'
+  Amount: string
+  Destination: string
+  SettleDelay: number
+  PublicKey: string
+  CancelAfter?: number
+  DestinationTag?: number
+  SourceTag?: number
+}
+const assertValid = (tx: Partial<PaymentChannelCreateTransaction>): void =>
   assertTxIsValid(tx, validatePaymentChannelCreate)
-const assertInvalid = (tx: any, message: string): void =>
+const assertInvalid = (tx: Partial<PaymentChannelCreateTransaction>, message: string): void =>
   assertTxValidationError(tx, validatePaymentChannelCreate, message)

15-15: Use the specific transaction type instead of any.

Replace any with the suggested PaymentChannelCreateTransaction type for better type safety.

-  let channel: any
+  let channel: PaymentChannelCreateTransaction
packages/xrpl/test/models/DIDSet.test.ts (2)

4-6: Consider using a more specific type instead of any.

While any works, using a more specific type would improve type safety. Consider creating an interface for the transaction type or using the existing transaction type from the codebase.

-const assertValid = (tx: any): void => assertTxIsValid(tx, validateDIDSet)
-const assertInvalid = (tx: any, message: string): void =>
+interface DIDSetTransaction {
+  Account: string
+  Data?: string
+  DIDDocument?: string
+  URI?: string
+  Fee: string
+  Flags: number
+  Sequence: number
+  TransactionType: 'DIDSet'
+}
+const assertValid = (tx: DIDSetTransaction): void => assertTxIsValid(tx, validateDIDSet)
+const assertInvalid = (tx: DIDSetTransaction, message: string): void =>

51-60: Consider using undefined assignment instead of delete operator.

While the current implementation works, the delete operator can have performance implications. Although this is test code where performance is less critical, for consistency with best practices, consider using undefined assignments.

-    delete tx.Data
-    delete tx.DIDDocument
-    delete tx.URI
+    tx.Data = undefined
+    tx.DIDDocument = undefined
+    tx.URI = undefined
🧰 Tools
🪛 Biome (1.9.4)

[error] 52-52: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 53-53: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 54-54: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/trustSet.test.ts (2)

14-14: Consider using a more specific type instead of any.

Using any type bypasses TypeScript's type checking. Consider creating an interface or type for the TrustSet transaction to improve type safety.

Example:

interface TrustSetTransaction {
  TransactionType: 'TrustSet'
  Account: string
  LimitAmount: {
    currency: string
    issuer: string
    value: string
  }
  QualityIn?: number
  QualityOut?: number
  Flags?: {
    tfSetFreeze?: boolean
    tfSetDeepFreeze?: boolean
  }
}

40-41: Consider using undefined assignment instead of delete operator.

Using the delete operator can impact performance. Consider using an undefined assignment instead.

-delete trustSet.LimitAmount
+trustSet.LimitAmount = undefined
🧰 Tools
🪛 Biome (1.9.4)

[error] 40-40: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/NFTokenModify.test.ts (1)

11-61: Consider adding test for URI length validation.

While the test coverage is good for basic URI validation, consider adding a test case for maximum URI length validation, which is a common requirement for NFT metadata.

Here's a suggested test case:

it(`throws w/ URI exceeding maximum length`, function () {
  const invalid = {
    TransactionType: 'NFTokenModify',
    Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm',
    NFTokenID: TOKEN_ID,
    Fee: '5000000',
    Sequence: 2470665,
    URI: stringToHex('x'.repeat(257)), // Assuming 256 bytes is the maximum
  } as any

  assertInvalid(invalid, 'NFTokenModify: URI length cannot exceed 256 bytes')
})
🧰 Tools
🪛 GitHub Actions: Node.js CI

[error] 22-22: Cannot find name 'assert'.


[error] 22-22: Cannot find name 'validate'.


[error] 33-33: Cannot find name 'assertInvalid'.


[error] 46-46: Cannot find name 'assertInvalid'.


[error] 59-59: Cannot find name 'assertInvalid'.


[error] 22-22: Cannot find name 'assert'.


[error] 22-22: Cannot find name 'validate'.


[error] 33-33: Cannot find name 'assertInvalid'.


[error] 46-46: Cannot find name 'assertInvalid'.


[error] 59-59: Cannot find name 'assertInvalid'.


[error] 22-22: Cannot find name 'assert'.


[error] 22-22: Cannot find name 'validate'.


[error] 33-33: Cannot find name 'assertInvalid'.


[error] 46-46: Cannot find name 'assertInvalid'.


[error] 59-59: Cannot find name 'assertInvalid'.

packages/xrpl/test/models/baseTransaction.test.ts (1)

11-248: Consider adding more test cases for edge cases.

The test coverage is comprehensive, but consider adding test cases for:

  1. Multiple invalid fields in a single transaction
  2. Boundary values for numeric fields
  3. Empty strings vs null/undefined values

Would you like me to help generate these additional test cases?

packages/xrpl/test/models/permissionedDomainDelete.test.ts (1)

31-31: Replace delete operator with undefined assignment.

The delete operator can impact performance. Consider using an undefined assignment instead.

-delete tx.DomainID
+tx.DomainID = undefined
🧰 Tools
🪛 Biome (1.9.4)

[error] 31-31: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/AMMDelete.test.ts (1)

37-38: Consider using undefined assignment instead of delete operator.

For better performance, consider replacing delete operations with undefined assignments:

-    delete ammDelete.Asset
+    ammDelete.Asset = undefined
-    delete ammDelete.Asset2
+    ammDelete.Asset2 = undefined

Also applies to: 49-50

🧰 Tools
🪛 Biome (1.9.4)

[error] 37-37: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/ticketCreate.test.ts (1)

29-30: Consider using undefined assignment instead of delete operator.

For better performance, consider replacing the delete operation with an undefined assignment:

-    delete ticketCreate.TicketCount
+    ticketCreate.TicketCount = undefined
🧰 Tools
🪛 Biome (1.9.4)

[error] 29-29: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/paymentChannelFund.test.ts (1)

33-34: Consider using undefined assignments instead of delete operators.

For better performance, consider replacing multiple delete operations with undefined assignments:

-    delete channel.Expiration
+    channel.Expiration = undefined
-    delete channel.Amount
+    channel.Amount = undefined
-    delete channel.Channel
+    channel.Channel = undefined

Also applies to: 39-40, 45-46

🧰 Tools
🪛 Biome (1.9.4)

[error] 33-33: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/XChainModifyBridge.test.ts (1)

44-45: Consider using undefined assignment instead of delete operator.

For better performance, consider replacing the delete operation with an undefined assignment:

-    delete tx.XChainBridge
+    tx.XChainBridge = undefined
🧰 Tools
🪛 Biome (1.9.4)

[error] 44-44: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/XChainCreateBridge.test.ts (1)

44-44: Consider using undefined assignment instead of delete operator.

The delete operator can impact performance. While this is less critical in test code, consider using undefined assignment for consistency with static analysis recommendations.

-    delete tx.XChainBridge
+    tx.XChainBridge = undefined

-    delete tx.SignatureReward
+    tx.SignatureReward = undefined

Also applies to: 56-56

🧰 Tools
🪛 Biome (1.9.4)

[error] 44-44: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/XChainCommit.test.ts (1)

43-43: Consider using undefined assignment instead of delete operator.

Similar to other test files, replace delete with undefined assignments for better performance.

-    delete tx.XChainBridge
+    tx.XChainBridge = undefined

-    delete tx.XChainClaimID
+    tx.XChainClaimID = undefined

-    delete tx.Amount
+    tx.Amount = undefined

Also applies to: 55-55, 73-73

🧰 Tools
🪛 Biome (1.9.4)

[error] 43-43: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/AMMCreate.test.ts (1)

36-36: Consider using undefined assignment instead of delete operator.

Replace delete with undefined assignments for consistency with static analysis recommendations.

-    delete ammCreate.Amount
+    ammCreate.Amount = undefined

-    delete ammCreate.Amount2
+    ammCreate.Amount2 = undefined

-    delete ammCreate.TradingFee
+    ammCreate.TradingFee = undefined

Also applies to: 48-48, 60-60

🧰 Tools
🪛 Biome (1.9.4)

[error] 36-36: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/XChainClaim.test.ts (1)

44-44: Consider using undefined assignment instead of delete operator.

Replace delete with undefined assignments for better performance and consistency.

-    delete tx.XChainBridge
+    tx.XChainBridge = undefined

-    delete tx.XChainClaimID
+    tx.XChainClaimID = undefined

-    delete tx.Destination
+    tx.Destination = undefined

-    delete tx.Amount
+    tx.Amount = undefined

Also applies to: 56-56, 68-68, 86-86

🧰 Tools
🪛 Biome (1.9.4)

[error] 44-44: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/AMMClawback.test.ts (1)

45-45: Consider using undefined assignment for better performance.

Multiple instances of the delete operator are used to remove properties. While acceptable in tests, consider using undefined assignment for better performance:

-delete ammClawback.Amount
+ammClawback.Amount = undefined

Also applies to: 55-55, 73-73, 91-91

🧰 Tools
🪛 Biome (1.9.4)

[error] 45-45: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/AMMBid.test.ts (1)

68-68: Consider using undefined assignment for better performance.

Similar to other test files, replace delete operator with undefined assignment:

-delete bid.Asset
+bid.Asset = undefined

Also applies to: 80-80

🧰 Tools
🪛 Biome (1.9.4)

[error] 68-68: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/XChainAddClaimAttestation.test.ts (1)

4-7: LGTM! Consider performance improvements.

The introduction of helper functions and explicit typing improves code maintainability and type safety.

For better performance, consider replacing delete operations with undefined assignments in test cases:

-delete tx.Amount
+tx.Amount = undefined

This change would address the static analysis warnings about the delete operator's performance impact.

Also applies to: 15-15

packages/xrpl/test/testUtils.ts (2)

60-69: Consider improving type safety and documentation.

The function implementation looks good, but consider these improvements:

  1. Replace any with a more specific type for the tx parameter
  2. Add example usage in the JSDoc comment
 /**
  * Check that a transaction error validation fails properly.
  *
+ * @example
+ * ```typescript
+ * const tx = { TransactionType: 'Payment', ... }
+ * assertTxIsValid(tx, validatePayment)
+ * ```
  *
  * @param tx The transaction that should fail validation.
  * @param validateTx The transaction-specific validation function (e.g. `validatePayment`).
  */
-export function assertTxIsValid(tx: any, validateTx: (tx: any) => void): void {
+export function assertTxIsValid(
+  tx: Record<string, unknown>,
+  validateTx: (tx: Record<string, unknown>) => void
+): void {
   assert.doesNotThrow(() => validateTx(tx))
   assert.doesNotThrow(() => validate(tx))
 }

71-85: Consider improving type safety and documentation.

The function implementation looks good, but consider these improvements:

  1. Replace any with a more specific type for the tx parameter
  2. Add example usage in the JSDoc comment
 /**
  * Check that a transaction error validation fails properly.
  *
+ * @example
+ * ```typescript
+ * const tx = { TransactionType: 'Payment' } // missing required field
+ * assertTxValidationError(tx, validatePayment, 'invalid field')
+ * ```
  *
  * @param tx The transaction that should fail validation.
  * @param validateTx The transaction-specific validation function (e.g. `validatePayment`).
  * @param errorMessage The error message that should be included in the error.
  */
 export function assertTxValidationError(
-  tx: any,
-  validateTx: (tx: any) => void,
+  tx: Record<string, unknown>,
+  validateTx: (tx: Record<string, unknown>) => void,
   errorMessage: string,
 ): void {
   assert.throws(() => validateTx(tx), ValidationError, errorMessage)
   assert.throws(() => validate(tx), ValidationError, errorMessage)
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8216446 and 6dd9b2c.

📒 Files selected for processing (57)
  • .vscode/settings.json (1 hunks)
  • packages/xrpl/test/models/AMMBid.test.ts (5 hunks)
  • packages/xrpl/test/models/AMMClawback.test.ts (2 hunks)
  • packages/xrpl/test/models/AMMCreate.test.ts (2 hunks)
  • packages/xrpl/test/models/AMMDelete.test.ts (2 hunks)
  • packages/xrpl/test/models/AMMDeposit.test.ts (5 hunks)
  • packages/xrpl/test/models/AMMVote.test.ts (2 hunks)
  • packages/xrpl/test/models/AMMWithdraw.test.ts (5 hunks)
  • packages/xrpl/test/models/CredentialAccept.test.ts (2 hunks)
  • packages/xrpl/test/models/CredentialCreate.test.ts (2 hunks)
  • packages/xrpl/test/models/CredentialDelete.test.ts (2 hunks)
  • packages/xrpl/test/models/DIDDelete.test.ts (2 hunks)
  • packages/xrpl/test/models/DIDSet.test.ts (2 hunks)
  • packages/xrpl/test/models/MPTokenAuthorize.test.ts (6 hunks)
  • packages/xrpl/test/models/MPTokenIssuanceCreate.test.ts (9 hunks)
  • packages/xrpl/test/models/MPTokenIssuanceDestroy.test.ts (1 hunks)
  • packages/xrpl/test/models/MPTokenIssuanceSet.test.ts (3 hunks)
  • packages/xrpl/test/models/NFTokenAcceptOffer.test.ts (6 hunks)
  • packages/xrpl/test/models/NFTokenBurn.test.ts (1 hunks)
  • packages/xrpl/test/models/NFTokenCancelOffer.test.ts (2 hunks)
  • packages/xrpl/test/models/NFTokenCreateOffer.test.ts (9 hunks)
  • packages/xrpl/test/models/NFTokenMint.test.ts (6 hunks)
  • packages/xrpl/test/models/NFTokenModify.test.ts (5 hunks)
  • packages/xrpl/test/models/XChainAccountCreateCommit.test.ts (2 hunks)
  • packages/xrpl/test/models/XChainAddAccountCreateAttestation.test.ts (2 hunks)
  • packages/xrpl/test/models/XChainAddClaimAttestation.test.ts (2 hunks)
  • packages/xrpl/test/models/XChainClaim.test.ts (2 hunks)
  • packages/xrpl/test/models/XChainCommit.test.ts (2 hunks)
  • packages/xrpl/test/models/XChainCreateBridge.test.ts (2 hunks)
  • packages/xrpl/test/models/XChainCreateClaimID.test.ts (2 hunks)
  • packages/xrpl/test/models/XChainModifyBridge.test.ts (2 hunks)
  • packages/xrpl/test/models/accountDelete.test.ts (5 hunks)
  • packages/xrpl/test/models/accountSet.test.ts (2 hunks)
  • packages/xrpl/test/models/baseTransaction.test.ts (8 hunks)
  • packages/xrpl/test/models/checkCancel.test.ts (3 hunks)
  • packages/xrpl/test/models/checkCash.test.ts (5 hunks)
  • packages/xrpl/test/models/checkCreate.test.ts (7 hunks)
  • packages/xrpl/test/models/clawback.test.ts (8 hunks)
  • packages/xrpl/test/models/depositPreauth.test.ts (9 hunks)
  • packages/xrpl/test/models/escrowCancel.test.ts (2 hunks)
  • packages/xrpl/test/models/escrowCreate.test.ts (3 hunks)
  • packages/xrpl/test/models/escrowFinish.test.ts (5 hunks)
  • packages/xrpl/test/models/offerCancel.test.ts (2 hunks)
  • packages/xrpl/test/models/offerCreate.test.ts (3 hunks)
  • packages/xrpl/test/models/oracleDelete.test.ts (2 hunks)
  • packages/xrpl/test/models/oracleSet.test.ts (3 hunks)
  • packages/xrpl/test/models/payment.test.ts (5 hunks)
  • packages/xrpl/test/models/paymentChannelClaim.test.ts (3 hunks)
  • packages/xrpl/test/models/paymentChannelCreate.test.ts (2 hunks)
  • packages/xrpl/test/models/paymentChannelFund.test.ts (2 hunks)
  • packages/xrpl/test/models/permissionedDomainDelete.test.ts (2 hunks)
  • packages/xrpl/test/models/permissionedDomainSet.test.ts (2 hunks)
  • packages/xrpl/test/models/setRegularKey.test.ts (2 hunks)
  • packages/xrpl/test/models/signerListSet.test.ts (3 hunks)
  • packages/xrpl/test/models/ticketCreate.test.ts (1 hunks)
  • packages/xrpl/test/models/trustSet.test.ts (2 hunks)
  • packages/xrpl/test/testUtils.ts (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .vscode/settings.json
🚧 Files skipped from review as they are similar to previous changes (15)
  • packages/xrpl/test/models/checkCreate.test.ts
  • packages/xrpl/test/models/setRegularKey.test.ts
  • packages/xrpl/test/models/escrowFinish.test.ts
  • packages/xrpl/test/models/accountSet.test.ts
  • packages/xrpl/test/models/signerListSet.test.ts
  • packages/xrpl/test/models/checkCash.test.ts
  • packages/xrpl/test/models/CredentialDelete.test.ts
  • packages/xrpl/test/models/checkCancel.test.ts
  • packages/xrpl/test/models/NFTokenAcceptOffer.test.ts
  • packages/xrpl/test/models/CredentialAccept.test.ts
  • packages/xrpl/test/models/depositPreauth.test.ts
  • packages/xrpl/test/models/NFTokenCreateOffer.test.ts
  • packages/xrpl/test/models/accountDelete.test.ts
  • packages/xrpl/test/models/CredentialCreate.test.ts
  • packages/xrpl/test/models/offerCreate.test.ts
🧰 Additional context used
🧠 Learnings (9)
packages/xrpl/test/models/MPTokenIssuanceDestroy.test.ts (1)
Learnt from: achowdhry-ripple
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts:69-102
Timestamp: 2024-12-05T16:48:12.951Z
Learning: When adding validation in `validate*` functions in `packages/xrpl/src/models/transactions/`, utilize existing helper functions (e.g., `validateOptionalField`, `validateType`, `isNumber`, `isInteger`) for type checking and validation where appropriate.
packages/xrpl/test/models/clawback.test.ts (1)
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/clawback.test.ts:165-178
Timestamp: 2024-12-06T19:27:11.147Z
Learning: In the integration tests for `clawback.test.ts`, it's acceptable to use `@ts-expect-error` to bypass type checking when verifying ledger entries, and no additional type safety improvements are needed.
packages/xrpl/test/models/MPTokenIssuanceCreate.test.ts (1)
Learnt from: achowdhry-ripple
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts:69-102
Timestamp: 2024-12-05T16:48:12.951Z
Learning: When adding validation in `validate*` functions in `packages/xrpl/src/models/transactions/`, utilize existing helper functions (e.g., `validateOptionalField`, `validateType`, `isNumber`, `isInteger`) for type checking and validation where appropriate.
packages/xrpl/test/models/MPTokenIssuanceSet.test.ts (1)
Learnt from: achowdhry-ripple
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts:69-102
Timestamp: 2024-12-05T16:48:12.951Z
Learning: When adding validation in `validate*` functions in `packages/xrpl/src/models/transactions/`, utilize existing helper functions (e.g., `validateOptionalField`, `validateType`, `isNumber`, `isInteger`) for type checking and validation where appropriate.
packages/xrpl/test/models/permissionedDomainSet.test.ts (3)
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2874
File: packages/xrpl/test/integration/transactions/permissionedDomain.test.ts:25-80
Timestamp: 2025-01-08T02:12:28.489Z
Learning: For PermissionedDomain feature (XLS-80d), complex error cases like invalid credential format, duplicate credentials, and non-existent DomainID are tested in the rippled C++ implementation rather than being duplicated across SDK implementations like xrpl.js.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2874
File: packages/xrpl/test/models/permissionedDomainDelete.test.ts:15-20
Timestamp: 2025-01-08T02:11:21.997Z
Learning: In validation test cases for XRPL transactions, using generic JSON input (e.g., `as any`) is preferred over strict typing as it better represents real-world scenarios where the `validate` method needs to handle arbitrary JSON/map/dictionary input from users.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2874
File: packages/xrpl/test/integration/transactions/permissionedDomain.test.ts:25-80
Timestamp: 2025-01-08T02:12:28.489Z
Learning: The rippled C++ implementation (PR #5161) includes comprehensive test coverage for PermissionedDomain (XLS-80d) error cases. The JS SDK tests focus on the happy path since the error cases are already validated at the rippled level, following the principle of not duplicating complex validation testing across SDK implementations.
packages/xrpl/test/models/XChainCommit.test.ts (1)
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2874
File: packages/xrpl/src/models/transactions/common.ts:18-18
Timestamp: 2025-01-16T04:11:37.316Z
Learning: Test libraries like chai should not be used in source code. For runtime checks in browser-compatible code, use vanilla JS error throwing instead of assertion libraries.
packages/xrpl/test/models/MPTokenAuthorize.test.ts (3)
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/models/MPTokenAuthorize.test.ts:60-71
Timestamp: 2024-12-06T18:44:55.095Z
Learning: In the XRPL.js library's TypeScript test file `packages/xrpl/test/models/MPTokenAuthorize.test.ts`, negative test cases for invalid `Account` address format, invalid `Holder` address format, invalid `MPTokenIssuanceID` format, and invalid flag combinations are not necessary.
Learnt from: achowdhry-ripple
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts:69-102
Timestamp: 2024-12-05T16:48:12.951Z
Learning: When adding validation in `validate*` functions in `packages/xrpl/src/models/transactions/`, utilize existing helper functions (e.g., `validateOptionalField`, `validateType`, `isNumber`, `isInteger`) for type checking and validation where appropriate.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/mptokenAuthorize.test.ts:29-118
Timestamp: 2024-12-06T19:25:15.376Z
Learning: In the XRPLF/xrpl.js TypeScript client library, when writing tests (e.g., in `packages/xrpl/test/integration/transactions/`), we generally do not need to test rippled server behaviors, because those behaviors are covered by rippled's own integration and unit tests.
packages/xrpl/test/models/permissionedDomainDelete.test.ts (2)
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2874
File: packages/xrpl/test/models/permissionedDomainDelete.test.ts:15-20
Timestamp: 2025-01-08T02:11:21.997Z
Learning: In validation test cases for XRPL transactions, using generic JSON input (e.g., `as any`) is preferred over strict typing as it better represents real-world scenarios where the `validate` method needs to handle arbitrary JSON/map/dictionary input from users.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2874
File: packages/xrpl/test/integration/transactions/permissionedDomain.test.ts:25-80
Timestamp: 2025-01-08T02:12:28.489Z
Learning: The rippled C++ implementation (PR #5161) includes comprehensive test coverage for PermissionedDomain (XLS-80d) error cases. The JS SDK tests focus on the happy path since the error cases are already validated at the rippled level, following the principle of not duplicating complex validation testing across SDK implementations.
packages/xrpl/test/models/AMMClawback.test.ts (1)
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/clawback.test.ts:165-178
Timestamp: 2024-12-06T19:27:11.147Z
Learning: In the integration tests for `clawback.test.ts`, it's acceptable to use `@ts-expect-error` to bypass type checking when verifying ledger entries, and no additional type safety improvements are needed.
🪛 GitHub Actions: Node.js CI
packages/xrpl/test/models/MPTokenIssuanceDestroy.test.ts

[error] 16-16: Cannot find name 'assert'.


[error] 16-16: Cannot find name 'validate'.


[error] 25-25: Cannot find name 'assertInvalid'.


[error] 16-16: Cannot find name 'assert'.


[error] 16-16: Cannot find name 'validate'.


[error] 25-25: Cannot find name 'assertInvalid'.


[error] 16-16: Cannot find name 'assert'.


[error] 16-16: Cannot find name 'validate'.


[error] 25-25: Cannot find name 'assertInvalid'.


[error] 16-16: Cannot find name 'assert'.


[error] 16-16: Cannot find name 'validate'.


[error] 25-25: Cannot find name 'assertInvalid'.

packages/xrpl/test/models/NFTokenBurn.test.ts

[error] 20-20: Cannot find name 'assert'.


[error] 20-20: Cannot find name 'validate'.


[error] 32-32: Cannot find name 'assertInvalid'.


[error] 20-20: Cannot find name 'assert'.


[error] 20-20: Cannot find name 'validate'.


[error] 32-32: Cannot find name 'assertInvalid'.


[error] 20-20: Cannot find name 'assert'.


[error] 20-20: Cannot find name 'validate'.


[error] 32-32: Cannot find name 'assertInvalid'.


[error] 20-20: Cannot find name 'assert'.


[error] 20-20: Cannot find name 'validate'.


[error] 32-32: Cannot find name 'assertInvalid'.

packages/xrpl/test/models/clawback.test.ts

[warning] 4-4: 'assertValid' is assigned a value but never used. Allowed unused vars must match /^_/u


[error] 25-25: Functions that return promises must be async


[error] 25-25: Unsafe return of an any typed value


[error] 81-81: Functions that return promises must be async


[error] 81-81: Unsafe return of an any typed value

packages/xrpl/test/models/MPTokenIssuanceSet.test.ts

[error] 19-19: Cannot find name 'assert'.


[error] 19-19: Cannot find name 'validate'.


[error] 29-29: Cannot find name 'assert'.


[error] 29-29: Cannot find name 'validate'.


[error] 39-39: Cannot find name 'assert'.


[error] 39-39: Cannot find name 'validate'.


[error] 48-48: Cannot find name 'assertInvalid'.


[error] 65-65: Cannot find name 'assertInvalid'.


[error] 69-69: Cannot find name 'assertInvalid'.


[error] 39-39: Cannot find name 'assert'.


[error] 39-39: Cannot find name 'validate'.


[error] 19-19: Cannot find name 'assert'.


[error] 19-19: Cannot find name 'validate'.


[error] 29-29: Cannot find name 'assert'.


[error] 29-29: Cannot find name 'validate'.


[error] 39-39: Cannot find name 'assert'.


[error] 39-39: Cannot find name 'validate'.


[error] 48-48: Cannot find name 'assertInvalid'.


[error] 65-65: Cannot find name 'assertInvalid'.


[error] 69-69: Cannot find name 'assertInvalid'.


[error] 39-39: Cannot find name 'assert'.


[error] 39-39: Cannot find name 'validate'.


[error] 19-19: Cannot find name 'assert'.


[error] 19-19: Cannot find name 'validate'.


[error] 29-29: Cannot find name 'assert'.


[error] 29-29: Cannot find name 'validate'.


[error] 39-39: Cannot find name 'assert'.


[error] 39-39: Cannot find name 'validate'.


[error] 48-48: Cannot find name 'assertInvalid'.


[error] 65-65: Cannot find name 'assertInvalid'.


[error] 69-69: Cannot find name 'assertInvalid'.


[error] 39-39: Cannot find name 'assert'.


[error] 39-39: Cannot find name 'validate'.

packages/xrpl/test/models/NFTokenMint.test.ts

[error] 4-4: Unable to resolve path to module '../../src/models/transactions/nftokenMint'


[error] 4-4: Missing file extension for '../../src/models/transactions/nftokenMint'


[error] 4-4: '../../src/models/transactions/nftokenMint' is not found

packages/xrpl/test/models/NFTokenCancelOffer.test.ts

[error] 20-20: Cannot find name 'assert'.


[error] 20-20: Cannot find name 'validate'.


[error] 32-32: Cannot find name 'assertInvalid'.


[error] 45-45: Cannot find name 'assertInvalid'.


[error] 20-20: Cannot find name 'assert'.


[error] 20-20: Cannot find name 'validate'.


[error] 32-32: Cannot find name 'assertInvalid'.


[error] 45-45: Cannot find name 'assertInvalid'.


[error] 20-20: Cannot find name 'assert'.


[error] 20-20: Cannot find name 'validate'.


[error] 32-32: Cannot find name 'assertInvalid'.


[error] 45-45: Cannot find name 'assertInvalid'.

packages/xrpl/test/models/MPTokenAuthorize.test.ts

[error] 2-2: Cannot find module '../../src/models/transactions/mptokenAuthorize' or its corresponding type declarations.


[error] 2-2: Cannot find module '../../src/models/transactions/mptokenAuthorize' or its corresponding type declarations.


[error] 2-2: Cannot find module '../../src/models/transactions/mptokenAuthorize' or its corresponding type declarations.

packages/xrpl/test/models/NFTokenModify.test.ts

[error] 22-22: Cannot find name 'assert'.


[error] 22-22: Cannot find name 'validate'.


[error] 33-33: Cannot find name 'assertInvalid'.


[error] 46-46: Cannot find name 'assertInvalid'.


[error] 59-59: Cannot find name 'assertInvalid'.


[error] 22-22: Cannot find name 'assert'.


[error] 22-22: Cannot find name 'validate'.


[error] 33-33: Cannot find name 'assertInvalid'.


[error] 46-46: Cannot find name 'assertInvalid'.


[error] 59-59: Cannot find name 'assertInvalid'.


[error] 22-22: Cannot find name 'assert'.


[error] 22-22: Cannot find name 'validate'.


[error] 33-33: Cannot find name 'assertInvalid'.


[error] 46-46: Cannot find name 'assertInvalid'.


[error] 59-59: Cannot find name 'assertInvalid'.

packages/xrpl/test/models/baseTransaction.test.ts

[error] 4-4: Cannot find module '../../src/models/transactions/BaseTransaction' or its corresponding type declarations.

🪛 Biome (1.9.4)
packages/xrpl/test/models/AMMWithdraw.test.ts

[error] 89-89: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 101-101: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/XChainClaim.test.ts

[error] 44-44: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 56-56: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 68-68: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 86-86: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/XChainCreateBridge.test.ts

[error] 44-44: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 56-56: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/permissionedDomainSet.test.ts

[error] 48-48: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/XChainModifyBridge.test.ts

[error] 44-44: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/DIDSet.test.ts

[error] 52-52: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 53-53: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 54-54: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/AMMVote.test.ts

[error] 37-37: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 49-49: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 61-61: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/XChainAccountCreateCommit.test.ts

[error] 45-45: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 57-57: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 75-75: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 87-87: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/AMMBid.test.ts

[error] 68-68: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 80-80: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/XChainAddClaimAttestation.test.ts

[error] 53-53: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 65-65: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 83-83: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 107-107: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 125-125: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 137-137: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 149-149: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 167-167: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 179-179: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/XChainCommit.test.ts

[error] 43-43: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 55-55: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 73-73: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/permissionedDomainDelete.test.ts

[error] 31-31: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/escrowCreate.test.ts

[error] 36-36: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 42-42: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 84-84: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 85-85: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/XChainCreateClaimID.test.ts

[error] 44-44: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 56-56: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 68-68: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/AMMClawback.test.ts

[error] 45-45: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 55-55: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 73-73: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 91-91: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/XChainAddAccountCreateAttestation.test.ts

[error] 59-59: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 71-71: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 89-89: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 107-107: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 125-125: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 143-143: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 161-161: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 179-179: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 197-197: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 215-215: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 233-233: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/payment.test.ts

[error] 73-73: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 83-83: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/AMMCreate.test.ts

[error] 36-36: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 48-48: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 60-60: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/AMMDelete.test.ts

[error] 37-37: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 49-49: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/AMMDeposit.test.ts

[error] 78-78: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 90-90: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/escrowCancel.test.ts

[error] 36-36: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 42-42: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/offerCancel.test.ts

[error] 47-47: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/oracleDelete.test.ts

[error] 29-29: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/oracleSet.test.ts

[error] 45-45: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 57-57: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 114-114: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 128-128: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 135-135: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 142-142: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 149-149: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/paymentChannelClaim.test.ts

[error] 46-46: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/paymentChannelCreate.test.ts

[error] 37-37: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 38-38: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 39-39: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 45-45: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 51-51: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 57-57: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 63-63: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/paymentChannelFund.test.ts

[error] 33-33: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 39-39: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 45-45: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/ticketCreate.test.ts

[error] 29-29: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/trustSet.test.ts

[error] 40-40: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

🪛 ESLint
packages/xrpl/test/models/NFTokenMint.test.ts

[error] 4-4: Missing file extension for "../../src/models/transactions/nftokenMint"

(import/extensions)

packages/xrpl/test/models/MPTokenAuthorize.test.ts

[error] 2-2: Missing file extension for "../../src/models/transactions/mptokenAuthorize"

(import/extensions)

packages/xrpl/test/models/baseTransaction.test.ts

[error] 4-4: Missing file extension for "../../src/models/transactions/BaseTransaction"

(import/extensions)

🪛 Gitleaks (8.21.2)
packages/xrpl/test/models/MPTokenAuthorize.test.ts

3-3: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

🔇 Additional comments (70)
packages/xrpl/test/models/AMMWithdraw.test.ts (2)

3-9: LGTM! Great refactoring of test utilities.

The introduction of assertTxIsValid and assertTxValidationError helper functions improves code maintainability and readability by centralizing validation logic.


22-86: LGTM! Clean refactoring of validation assertions.

The changes consistently apply the new validation pattern across all test cases while maintaining comprehensive test coverage.

packages/xrpl/test/models/NFTokenCancelOffer.test.ts (1)

35-46: LGTM! Test case properly validates empty NFTokenOffers field.

The test case correctly validates the empty NFTokenOffers field scenario and follows the standardized error message format.

🧰 Tools
🪛 GitHub Actions: Node.js CI

[error] 45-45: Cannot find name 'assertInvalid'.


[error] 45-45: Cannot find name 'assertInvalid'.


[error] 45-45: Cannot find name 'assertInvalid'.

packages/xrpl/test/models/AMMVote.test.ts (3)

4-6: LGTM! Helper functions improve code maintainability.

The introduction of assertValid and assertInvalid functions effectively reduces code duplication and improves readability.


16-30: LGTM! Well-structured test setup.

The beforeEach block provides a comprehensive setup with all required fields and valid values for testing AMMVote transactions.


32-82: LGTM! Comprehensive test coverage.

The test suite thoroughly covers all validation scenarios including valid transactions, missing fields, invalid types, and boundary conditions.

🧰 Tools
🪛 Biome (1.9.4)

[error] 37-37: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 49-49: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 61-61: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/XChainCreateClaimID.test.ts (4)

2-7: LGTM! Well-structured helper functions.

The introduction of assertValid and assertInvalid helper functions improves code maintainability by encapsulating common validation logic. This aligns well with the PR's objective of enhancing validation functions.


14-37: LGTM! Comprehensive test setup.

The test setup provides a complete valid transaction object with all required fields, and the explicit any type annotation improves type clarity.


39-78: LGTM! Comprehensive test coverage.

The test cases thoroughly validate both successful and error scenarios with consistent error message formatting. This aligns well with the PR's objective of enhancing validation functions.

🧰 Tools
🪛 Biome (1.9.4)

[error] 44-44: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 56-56: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 68-68: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


44-44: Regarding the delete operator usage in tests.

While static analysis flags the use of delete operator for performance reasons, in this test context:

  1. Performance impact is negligible as this is test code.
  2. Using delete clearly communicates the intent of testing missing fields.
  3. Using undefined assignment might not trigger the same validation behavior.

Therefore, I recommend keeping the current implementation.

Also applies to: 56-56, 68-68

🧰 Tools
🪛 Biome (1.9.4)

[error] 44-44: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/oracleDelete.test.ts (4)

2-6: LGTM! Good use of utility functions.

The introduction of assertTxIsValid and assertTxValidationError along with helper functions improves code reusability and readability. The type annotations are properly used.


14-14: LGTM! Good type annotation.

Adding the type annotation for the test case variable improves code clarity.


25-25: LGTM! Good use of the utility function.

Using assertValid simplifies the test case and makes it more readable.


31-31: LGTM! Good test case improvements.

The test cases are more readable with the assertInvalid utility function, and using 'abcd' as an invalid value makes the test more explicit.

Also applies to: 35-37

packages/xrpl/test/models/XChainAccountCreateCommit.test.ts (1)

40-96: LGTM! Comprehensive test coverage.

The test cases thoroughly validate:

  • Valid transaction structure
  • Required fields (XChainBridge, SignatureReward, Destination, Amount)
  • Field type validations
  • Consistent error message format

The refactored assertions using assertValid and assertInvalid improve code readability.

🧰 Tools
🪛 Biome (1.9.4)

[error] 45-45: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 57-57: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 75-75: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 87-87: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/AMMDeposit.test.ts (2)

40-75: LGTM! Well-structured positive test cases.

The refactoring improves readability while maintaining comprehensive test coverage for valid transaction scenarios.


77-146: LGTM! Well-structured negative test cases with standardized error messages.

The refactoring improves readability and maintains consistent error message format across all validation failures.

🧰 Tools
🪛 Biome (1.9.4)

[error] 78-78: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 90-90: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/escrowCreate.test.ts (2)

2-6: LGTM! Well-structured utility functions.

The introduction of assertValid and assertInvalid utility functions improves code reusability and readability while following the DRY principle.


65-69: Add missing validation test for FinishAfter.

The test case only checks validateEscrowCreate() but not validate(). For consistency with other test cases, add the missing validation test.

Apply this diff to add the missing test:

   it(`invalid FinishAfter`, function () {
     escrow.FinishAfter = 'abcd'

     assertInvalid(escrow, 'EscrowCreate: invalid field FinishAfter')
+    assert.throws(
+      () => validate(escrow),
+      ValidationError,
+      'EscrowCreate: invalid field FinishAfter',
+    )
   })
packages/xrpl/test/models/paymentChannelClaim.test.ts (1)

45-79: LGTM! The test cases are comprehensive and well-structured.

Note: The static analysis warning about using the delete operator can be safely ignored in test code. While using undefined assignment would be more performant, the delete operator better expresses the intent of removing fields for testing purposes, and the performance impact is negligible in test scenarios.

🧰 Tools
🪛 Biome (1.9.4)

[error] 46-46: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/escrowCancel.test.ts (6)

2-6: LGTM! Good use of utility functions.

The introduction of assertValid and assertInvalid helper functions improves code reusability and makes the test cases more maintainable.


14-14: LGTM! Appropriate use of let declaration.

The change from const to let is correct as the variable is modified in test cases.


26-26: LGTM! Good use of the new helper function.

The change to use assertValid makes the test case more concise and readable.


32-32: LGTM! Consistent use of helper functions.

The change maintains consistency with other test cases.


38-38: LGTM! Consistent error message format.

The error messages now follow a consistent format: "missing/invalid field {fieldName}".

Also applies to: 44-44, 50-50, 56-56


36-36: Note about delete operator usage.

Static analysis flagged the use of delete operator for potential performance impact. However, in test files:

  1. Performance is not critical
  2. delete provides clearer intent than setting to undefined
  3. Tests often need to simulate missing properties

Therefore, the current implementation is acceptable.

Also applies to: 42-42

🧰 Tools
🪛 Biome (1.9.4)

[error] 36-36: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/offerCancel.test.ts (5)

2-6: LGTM! Good refactoring of test utilities.

The introduction of assertValid and assertInvalid utility functions improves code readability and follows the DRY principle by encapsulating common validation logic.


14-14: LGTM! Type annotation is appropriate for test context.

Using any type provides the necessary flexibility for testing various scenarios.


29-29: No issues with this minor formatting change.


33-33: LGTM! Test cases are now more concise.

The use of assertValid utility function improves test readability while maintaining the same validation logic.

Also applies to: 38-38


42-43: LGTM! Test case and error message improvements.

The changes improve test clarity by:

  • Using a more obvious invalid value ('abcd' instead of a number)
  • Following the new consistent error message format
packages/xrpl/test/models/paymentChannelCreate.test.ts (2)

32-102: Well-structured test cases with consistent error messages!

The test cases are comprehensive and follow a consistent pattern for error messages. They cover:

  • Required fields (Amount, Destination, SettleDelay, PublicKey)
  • Optional fields (CancelAfter, DestinationTag, SourceTag)
  • Both valid and invalid scenarios
🧰 Tools
🪛 Biome (1.9.4)

[error] 37-37: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 38-38: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 39-39: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 45-45: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 51-51: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 57-57: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 63-63: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


37-39: Regarding the delete operator usage in tests.

The static analysis tool flags the use of the delete operator for potential performance impacts. However, since this is test code:

  1. The performance impact is negligible
  2. Using delete makes the intent clearer than setting fields to undefined
  3. It actually removes the property, which is what we want to test

Therefore, we can safely ignore these warnings.

Also applies to: 45-45, 51-51, 57-57, 63-63

🧰 Tools
🪛 Biome (1.9.4)

[error] 37-37: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 38-38: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 39-39: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/xrpl/test/models/DIDSet.test.ts (2)

14-31: LGTM! Clean test setup and valid case verification.

The test setup provides a comprehensive valid transaction object, and the assertion is clear and concise.


33-49: LGTM! Comprehensive invalid case testing.

The test cases effectively verify validation for each field with consistent error message formatting.

packages/xrpl/test/models/trustSet.test.ts (5)

2-6: LGTM! Great refactoring of test assertions.

The introduction of assertTxIsValid and assertTxValidationError helper functions improves code reusability and maintainability across test files.


36-36: LGTM! Clean test assertion.

The use of assertValid helper function makes the test more readable and consistent with other test files.


46-46: LGTM! Consistent error message format.

The error message follows the new standardized format: "invalid field ...".


50-51: LGTM! Clear test case for non-numeric QualityIn.

The test value 'abcd' clearly demonstrates the validation of non-numeric input, and the error message follows the standardized format.


55-56: LGTM! Clear test case for non-numeric QualityOut.

The test value 'dcba' clearly demonstrates the validation of non-numeric input, and the error message follows the standardized format.

packages/xrpl/test/models/MPTokenIssuanceSet.test.ts (1)

48-51: LGTM! Good use of the new assertInvalid helper.

The changes align with the PR objective by utilizing the newer assertInvalid helper function for validation testing. The error messages are consistent and descriptive.

Also applies to: 65-65, 69-69

🧰 Tools
🪛 GitHub Actions: Node.js CI

[error] 48-48: Cannot find name 'assertInvalid'.


[error] 48-48: Cannot find name 'assertInvalid'.


[error] 48-48: Cannot find name 'assertInvalid'.

packages/xrpl/test/models/NFTokenMint.test.ts (3)

7-9: LGTM! Well-designed helper functions.

The new helper functions assertValid and assertInvalid improve code maintainability by:

  • Reducing code duplication
  • Providing consistent validation behavior
  • Making test cases more readable

29-29: LGTM! Consistent URI handling.

The URI field is consistently converted to hex format using stringToHex across all test cases, improving code consistency.

Also applies to: 44-44, 60-60


32-32: LGTM! Clear and consistent error handling.

The test cases effectively use the new helper functions with clear, descriptive error messages that follow a consistent format:

  • Valid case verification
  • Missing field validation
  • Account/Issuer equality check
  • URI format validation

Also applies to: 47-47, 63-63, 79-79, 95-95

packages/xrpl/test/models/NFTokenModify.test.ts (2)

19-19: LGTM! Consistent use of string conversion utility.

The change from convertStringToHex to stringToHex aligns with the standardization effort across the codebase.


33-33: LGTM! Improved error handling consistency.

The changes to use assertInvalid with descriptive error messages align with the standardization of error handling across transaction tests.

Also applies to: 46-46, 59-59

🧰 Tools
🪛 GitHub Actions: Node.js CI

[error] 33-33: Cannot find name 'assertInvalid'.


[error] 33-33: Cannot find name 'assertInvalid'.


[error] 33-33: Cannot find name 'assertInvalid'.

packages/xrpl/test/models/MPTokenAuthorize.test.ts (3)

5-8: LGTM! Well-structured helper functions.

The helper functions assertValid and assertInvalid are well-designed:

  • Improve code reusability and readability
  • Follow TypeScript best practices with type annotations
  • Encapsulate validation logic effectively

10-16: LGTM! Clear test setup and documentation.

The test setup is well-structured with:

  • Clear constant naming
  • Descriptive JSDoc comments
  • Appropriate scope for the test suite

18-63: LGTM! Comprehensive test coverage.

The test cases are well-structured and provide good coverage:

  • Test valid transaction variations
  • Verify required field validation
  • Use realistic test data
  • Follow the new assertion pattern consistently

This aligns with the learnings that indicate we don't need to test certain negative cases (e.g., invalid address formats) as they're covered elsewhere.

packages/xrpl/test/models/baseTransaction.test.ts (6)

89-89: LGTM! Test case updated to use non-numeric string.

The test case now uses a non-numeric string to validate the Sequence field, which is a better test for type validation.


117-117: LGTM! Test case updated to use non-numeric string.

The test case now uses a non-numeric string to validate the LastLedgerSequence field, which is a better test for type validation.


159-159: LGTM! Test case updated to use non-numeric string.

The test case now uses a non-numeric string to validate the TicketSequence field, which is a better test for type validation.


193-193: LGTM! Error messages standardized.

The error messages have been updated to use the standardized format "invalid field Signers", which improves clarity and consistency.

Also applies to: 211-211


232-232: LGTM! Error message standardized.

The error message has been updated to use the standardized format "invalid field Memos", which improves clarity and consistency.


240-240: LGTM! Test case updated to use non-numeric string.

The test case now uses a non-numeric string to validate the NetworkID field, which is a better test for type validation.

packages/xrpl/test/models/permissionedDomainDelete.test.ts (1)

15-24: LGTM! Type casting approach aligns with best practices.

The use of as any for type casting aligns with the preferred approach for validation tests, as it better represents real-world scenarios where the validate method needs to handle arbitrary JSON input from users.

packages/xrpl/test/models/AMMDelete.test.ts (1)

44-45: LGTM! Consistent error message format.

The error messages follow a consistent pattern using "invalid field" format, which aligns with the PR's refactoring goals.

Also applies to: 56-57

packages/xrpl/test/models/ticketCreate.test.ts (1)

40-43: LGTM! Clear validation boundaries in error messages.

The error messages clearly specify the valid range for TicketCount (1 to 250), which helps developers understand the constraints.

packages/xrpl/test/models/paymentChannelFund.test.ts (1)

41-42: LGTM! Consistent error handling pattern.

The error messages follow a consistent pattern using "missing field" or "invalid field" format, which aligns with the PR's refactoring goals.

Also applies to: 47-48, 53-54, 59-60, 65-66

packages/xrpl/test/models/XChainModifyBridge.test.ts (1)

46-47: LGTM! Consistent error handling pattern.

The error messages follow a consistent pattern using "missing field" or "invalid field" format, which aligns with the PR's refactoring goals.

Also applies to: 52-53, 58-59, 64-67

packages/xrpl/test/models/XChainCreateBridge.test.ts (1)

4-7: LGTM! Helper functions improve test readability.

The introduction of assertValid and assertInvalid helper functions enhances code organization by encapsulating validation logic.

packages/xrpl/test/models/AMMCreate.test.ts (1)

71-81: LGTM! Comprehensive boundary testing for TradingFee.

Good test coverage for TradingFee validation, including both upper and lower bounds.

packages/xrpl/test/models/XChainClaim.test.ts (1)

79-83: LGTM! Good validation for DestinationTag type.

The test case properly validates that DestinationTag must be a number.

packages/xrpl/test/models/permissionedDomainSet.test.ts (2)

7-10: LGTM! Test utilities improve code maintainability.

The introduction of assertValid and assertInvalid utility functions enhances test readability and reduces code duplication.


18-18: Type declaration aligns with testing best practices.

Using any type for test input is appropriate here as it better represents real-world scenarios where validation needs to handle arbitrary JSON input.

packages/xrpl/test/models/AMMBid.test.ts (1)

37-58: LGTM! Comprehensive validation testing for AuthAccounts.

The test cases thoroughly cover various scenarios for AuthAccounts validation, including:

  • Array length limits
  • Invalid account types
  • Null/undefined handling
  • Sender address validation
packages/xrpl/test/models/oracleSet.test.ts (1)

6-8: LGTM! Well-structured test refactoring.

The helper functions and explicit typing enhance code maintainability while preserving test coverage.

Also applies to: 16-16

packages/xrpl/test/models/XChainAddAccountCreateAttestation.test.ts (1)

4-11: LGTM! Consistent with codebase standards.

The helper functions and explicit typing align with the established patterns across the test suite.

Also applies to: 19-19

packages/xrpl/test/models/payment.test.ts (1)

7-9: LGTM! Improved naming and consistent structure.

The renaming from paymentTransaction to payment enhances readability, while the helper functions and explicit typing maintain consistency with other test files.

Also applies to: 17-17

packages/xrpl/test/testUtils.ts (1)

8-13: LGTM!

The imports are well-organized and include the necessary dependencies for the new validation assertion functions.

Comment on lines 28 to 31
it('throws on invalid DIDDelete', function () {
tx.FakeField = 'blah'
assert.doesNotThrow(() => validateDIDDelete(tx))
assert.doesNotThrow(() => validate(tx))
assertValid(tx)
})
Copy link
Contributor

@coderabbitai coderabbitai bot Feb 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix incorrect assertion in invalid field test.

The test case is checking for invalid fields but using assertValid instead of assertInvalid. This will not properly verify that invalid fields are rejected.

Define and use assertInvalid function to properly test invalid fields:

+const assertInvalid = (tx: any, message: string): void =>
+  assertTxValidationError(tx, validateDIDDelete, message)

 it('throws on invalid DIDDelete', function () {
   tx.FakeField = 'blah'
-  assertValid(tx)
+  assertInvalid(tx, 'DIDDelete: invalid field FakeField')
 })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it('throws on invalid DIDDelete', function () {
tx.FakeField = 'blah'
assert.doesNotThrow(() => validateDIDDelete(tx))
assert.doesNotThrow(() => validate(tx))
assertValid(tx)
})
const assertInvalid = (tx: any, message: string): void =>
assertTxValidationError(tx, validateDIDDelete, message)
it('throws on invalid DIDDelete', function () {
tx.FakeField = 'blah'
assertInvalid(tx, 'DIDDelete: invalid field FakeField')
})

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way in JS to ensure that an object doesn't have any other keys?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mvadari Yes, there are a few ways to ensure an object only has specific keys in JavaScript:

  1. Compare keys with expected set:
function validateKeys(obj, expectedKeys) {
  const actualKeys = Object.keys(obj)
  const hasOnlyExpectedKeys = actualKeys.every(key => expectedKeys.includes(key))
  const hasAllExpectedKeys = expectedKeys.every(key => actualKeys.includes(key))
  return hasOnlyExpectedKeys && hasAllExpectedKeys
}
  1. Using TypeScript with strict object literal checks:
interface ValidTransaction {
  Account: string;
  Fee: string;
  Flags: number;
  Sequence: number;
  TransactionType: string;
}

// TypeScript will error if extra properties are present
const tx: ValidTransaction = {
  Account: "...",
  Fee: "10",
  Flags: 2147483648,
  Sequence: 4,
  TransactionType: "DIDDelete",
  extraField: "invalid" // Error: Object literal may only specify known properties
}
  1. Create a sanitized object with only allowed keys:
function sanitizeObject(obj, allowedKeys) {
  return Object.fromEntries(
    Object.entries(obj).filter(([key]) => allowedKeys.includes(key))
  )
}

For your test cases, I'd recommend using TypeScript interfaces with strict checks as it provides compile-time validation, or implementing a validation function that explicitly checks for unexpected keys if you need runtime validation.


✏️ Learnings added
Learnt from: mvadari
PR: XRPLF/xrpl.js#2895
File: packages/xrpl/test/models/DIDDelete.test.ts:28-31
Timestamp: 2025-02-12T23:30:40.497Z
Learning: In JavaScript/TypeScript transaction validation tests, object key validation can be performed using:
1. Object.keys() comparison with expected set
2. TypeScript interfaces with strict object literal checks
3. Object sanitization by filtering to allowed keys only

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (6)
packages/xrpl/src/models/transactions/batch.ts (1)

140-142: Update error message for consistency.

The error message at line 141 uses the old format, while line 123 was updated to be more descriptive. For consistency, this should follow the same pattern.

Apply this diff to align the error message:

     if (!isRecord(signerObj)) {
-      throw new ValidationError(`Batch: BatchSigners[${index}] is not object.`)
+      throw new ValidationError(
+        `Batch: invalid field BatchSigners[${index}], expected a valid Record`,
+      )
     }
packages/xrpl/test/models/MPTokenIssuanceCreate.test.ts (1)

118-140: Add a test: TransferFee present as 0 still requires tfMPTCanTransfer.

Spec says the field must not be present without the flag; 0 currently passes due to truthy check.

Proposed test:

+  it('throws w/ TransferFee=0 without tfMPTCanTransfer', function () {
+    const invalid = {
+      TransactionType: 'MPTokenIssuanceCreate',
+      Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm',
+      TransferFee: 0,
+    } as any
+    assertInvalid(
+      invalid,
+      'MPTokenIssuanceCreate: TransferFee cannot be provided without enabling tfMPTCanTransfer flag',
+    )
+  })
packages/xrpl/src/models/transactions/vaultCreate.ts (2)

123-136: Empty MPTokenMetadata allowed; violates the error text and differs from IssuanceCreate.

If isHex('') returns true, empty metadata passes. Enforce non-empty to match message and IssuanceCreate behavior.

   if (tx.MPTokenMetadata !== undefined) {
     const metaHex = tx.MPTokenMetadata
-    if (!isHex(metaHex)) {
+    if (!isHex(metaHex) || metaHex.length === 0) {
       throw new ValidationError(
-        'VaultCreate: MPTokenMetadata must be a valid non-empty hex string',
+        'VaultCreate: MPTokenMetadata must be a valid non-empty hex string',
       )
     }

103-112: Now I need to search the codebase directly to verify the validators and the learnings:

Based on my verification using the script execution and the retrieved learnings, I can now generate the rewritten review comment.

Inconsistent and under-permissive DomainID validation across transaction types.

validateVaultCreate uses isHexString (validates hex only, omits length check), while payment and offerCreate use isDomainID (validates both hex and length). Per rippled behavior and confirmed learnings, Domain ID validation should only enforce length (64 characters) at the JS validation layer; hex validation occurs at the serialization layer through Hash types in ripple-binary-codec.

Current state: three transactions under-validate, two over-validate.

Update all DomainID call sites to use consistent validation. Consider creating a length-only validator (e.g., validateDomainIDLength) or refining isDomainID to match rippled enforcement. Priority: align validateVaultCreate, validateVaultSet, and validatePermissionedDomainSet with payment and offerCreate—at minimum, add length validation.

packages/xrpl/test/models/vaultCreate.test.ts (1)

101-105: Update DomainID test samples to required 64-character length.

The test uses 16-character DomainID values ('ABCDEF1234567890'), but the standard requires 64 characters—enforced by the isDomainID validator used in Payment and OfferCreate transactions. Both test instances at lines 102 and 108 need updating.

  it('allows DomainID when tfVaultPrivate flag set', function () {
-   tx.DomainID = 'ABCDEF1234567890'
+   tx.DomainID = 'ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890'
    tx.Flags = VaultCreateFlags.tfVaultPrivate
    assertValid(tx)
  })

  it('throws w/ DomainID set but tfVaultPrivate flag missing', function () {
-   tx.DomainID = 'ABCDEF1234567890'
+   tx.DomainID = 'ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890'
    tx.Flags = 0
    assertInvalid(
      tx,
      'VaultCreate: Cannot set DomainID unless tfVaultPrivate flag is set.',
    )
  })
packages/xrpl/src/models/transactions/common.ts (1)

780-823: Inconsistent terminology in credential validation error messages

The validateCredentialsList function handles both CredentialIDs (strings) and Credentials (AuthorizeCredential objects) based on the isStringID parameter. However, the error messages are inconsistent:

  • Line 792 correctly uses "CredentialIDs" in the field-specific error
  • Lines 797, 801, 808, 813, 820 use the generic term "Credentials"

Since line 792 distinguishes by using "CredentialIDs" when appropriate, the other error messages should also be parameterized to use "CredentialIDs" when isStringID is true, or consistently use the generic term throughout. This inconsistency propagates to test files (e.g., payment.test.ts lines 258, 265, 275, 286).

Consider parameterizing error messages:

+  const fieldName = isStringID ? 'CredentialIDs' : 'Credentials'
   if (!isArray(credentials)) {
     throw new ValidationError(
-      `${transactionType}: invalid field CredentialIDs, expected a valid array`,
+      `${transactionType}: invalid field ${fieldName}, expected a valid array`,
     )
   }
   if (credentials.length > maxCredentials) {
     throw new ValidationError(
-      `${transactionType}: Credentials length cannot exceed ${maxCredentials} elements`,
+      `${transactionType}: ${fieldName} length cannot exceed ${maxCredentials} elements`,
     )
   } else if (credentials.length === 0) {
     throw new ValidationError(
-      `${transactionType}: Credentials cannot be an empty array`,
+      `${transactionType}: ${fieldName} cannot be an empty array`,
     )
   }
   // ... continue for other error messages
♻️ Duplicate comments (1)
packages/xrpl/test/models/payment.test.ts (1)

258-286: Inconsistent terminology: "Credentials" vs "CredentialIDs"

Lines 258, 265, 275, and 286 use "Credentials" in error messages, but line 240 correctly uses "CredentialIDs". Since the actual field name is CredentialIDs (as shown on line 236), all error messages should consistently reference "CredentialIDs" for clarity and to help developers identify the exact field causing validation failures.

Apply these changes for consistency:

-    const errorMessage = 'Payment: Credentials length cannot exceed 8 elements'
+    const errorMessage = 'Payment: CredentialIDs length cannot exceed 8 elements'
-    const errorMessage = 'Payment: Credentials cannot be an empty array'
+    const errorMessage = 'Payment: CredentialIDs cannot be an empty array'
-    const errorMessage = 'Payment: Invalid Credentials ID list format'
+    const errorMessage = 'Payment: Invalid CredentialIDs list format'
-    const errorMessage =
-      'Payment: Credentials cannot contain duplicate elements'
+    const errorMessage =
+      'Payment: CredentialIDs cannot contain duplicate elements'

Based on past review comments.

🧹 Nitpick comments (5)
packages/xrpl/test/testUtils.ts (1)

83-92: Static analysis warning is a false positive; regex construction is safe.

The ReDoS warning from ast-grep can be safely dismissed because:

  • All regex metacharacters are properly escaped using [.*+?^${}()|[\]\\] before constructing the RegExp
  • The resulting pattern ^<escaped_string>$ with anchors and escaped content cannot cause catastrophic backtracking
  • This is test utility code with controlled inputs

The regex construction and usage logic is correct and secure.

Optional: Minor documentation nit – Line 86's comment says "TS complains if it's included" but require-unicode-regexp is an ESLint rule, not a TypeScript compiler constraint. Consider clarifying this refers to ESLint configuration.

packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts (2)

146-151: Fold empty-hex validation into validateOptionalField to avoid branching on isHex('').

Single-source the error and drop the extra emptiness block.

-  validateOptionalField(tx, 'MPTokenMetadata', isHexString)
+  validateOptionalField(
+    tx,
+    'MPTokenMetadata',
+    (v): v is string => isHexString(v) && v.length > 0,
+    { invalidMessage: 'expected a valid non-empty hex string' },
+  )
-
-  if (isHexString(tx.MPTokenMetadata) && tx.MPTokenMetadata === '') {
-    throw new ValidationError(
-      'MPTokenIssuanceCreate: MPTokenMetadata must not be empty string',
-    )
-  }

152-160: Remove redundant isHex check; keep only the length cap.

isHex already enforced above; only enforce byte-length here.

-  if (
-    typeof tx.MPTokenMetadata === 'string' &&
-    (!isHex(tx.MPTokenMetadata) ||
-      tx.MPTokenMetadata.length / 2 > MAX_MPT_META_BYTE_LENGTH)
-  ) {
+  if (
+    typeof tx.MPTokenMetadata === 'string' &&
+    tx.MPTokenMetadata.length / 2 > MAX_MPT_META_BYTE_LENGTH
+  ) {
     throw new ValidationError(
       `MPTokenIssuanceCreate: MPTokenMetadata (hex format) must be non-empty and no more than ${MAX_MPT_META_BYTE_LENGTH} bytes.`,
     )
   }
packages/xrpl/src/models/transactions/payment.ts (1)

211-214: Use consistent txType for DomainID errors.

Set txType to 'Payment' to match other messages.

-  validateOptionalField(tx, 'DomainID', isDomainID, {
-    txType: 'PaymentTransaction',
+  validateOptionalField(tx, 'DomainID', isDomainID, {
+    txType: 'Payment',
     paramName: 'DomainID',
   })
packages/xrpl/src/models/transactions/common.ts (1)

442-483: Consider minification-safe error message approach

The invalidMessagesMap relies on checkValidity.name (line 527) to look up error messages. As noted in previous reviews, function names can be mangled by minifiers, which would cause fallback to generic "invalid field" messages without the helpful expected-type suffix.

For a minification-safe approach, consider attaching a custom _msg property to validator functions or using a WeakMap to associate validators with messages. However, given this is working correctly in the current build pipeline and you've chosen "Chill" review mode, this can be deferred to a future refactor if minification issues arise.

Based on past review comments.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 33a98b5 and 4168bc1.

📒 Files selected for processing (21)
  • packages/xrpl/src/models/common/index.ts (2 hunks)
  • packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts (5 hunks)
  • packages/xrpl/src/models/transactions/MPTokenIssuanceSet.ts (2 hunks)
  • packages/xrpl/src/models/transactions/accountSet.ts (2 hunks)
  • packages/xrpl/src/models/transactions/batch.ts (1 hunks)
  • packages/xrpl/src/models/transactions/common.ts (19 hunks)
  • packages/xrpl/src/models/transactions/delegateSet.ts (2 hunks)
  • packages/xrpl/src/models/transactions/escrowCreate.ts (2 hunks)
  • packages/xrpl/src/models/transactions/index.ts (1 hunks)
  • packages/xrpl/src/models/transactions/offerCreate.ts (3 hunks)
  • packages/xrpl/src/models/transactions/payment.ts (3 hunks)
  • packages/xrpl/src/models/transactions/vaultCreate.ts (2 hunks)
  • packages/xrpl/src/models/transactions/vaultDeposit.ts (2 hunks)
  • packages/xrpl/src/models/transactions/vaultWithdraw.ts (2 hunks)
  • packages/xrpl/src/sugar/autofill.ts (2 hunks)
  • packages/xrpl/test/models/MPTokenIssuanceCreate.test.ts (3 hunks)
  • packages/xrpl/test/models/batch.test.ts (2 hunks)
  • packages/xrpl/test/models/offerCreate.test.ts (3 hunks)
  • packages/xrpl/test/models/payment.test.ts (6 hunks)
  • packages/xrpl/test/models/vaultCreate.test.ts (4 hunks)
  • packages/xrpl/test/testUtils.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (9)
  • packages/xrpl/src/models/transactions/accountSet.ts
  • packages/xrpl/src/models/transactions/escrowCreate.ts
  • packages/xrpl/src/models/transactions/offerCreate.ts
  • packages/xrpl/test/models/batch.test.ts
  • packages/xrpl/src/models/transactions/vaultWithdraw.ts
  • packages/xrpl/src/models/transactions/MPTokenIssuanceSet.ts
  • packages/xrpl/test/models/offerCreate.test.ts
  • packages/xrpl/src/models/common/index.ts
  • packages/xrpl/src/models/transactions/delegateSet.ts
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: achowdhry-ripple
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts:69-102
Timestamp: 2024-12-05T16:48:12.951Z
Learning: When adding validation in `validate*` functions in `packages/xrpl/src/models/transactions/`, utilize existing helper functions (e.g., `validateOptionalField`, `validateType`, `isNumber`, `isInteger`) for type checking and validation where appropriate.
📚 Learning: 2025-07-10T22:04:59.994Z
Learnt from: ckeshava
PR: XRPLF/xrpl.js#3032
File: packages/xrpl/src/models/transactions/common.ts:689-698
Timestamp: 2025-07-10T22:04:59.994Z
Learning: In the XRPL.js library, the validateDomainID function in `packages/xrpl/src/models/transactions/common.ts` should only validate the length (64 characters) of domain IDs, not hex encoding. The rippled C++ implementation does not enforce any regex check on domain ID values, so additional hex validation is not required in the JS implementation.

Applied to files:

  • packages/xrpl/src/models/transactions/vaultCreate.ts
📚 Learning: 2024-12-05T16:48:12.951Z
Learnt from: achowdhry-ripple
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts:69-102
Timestamp: 2024-12-05T16:48:12.951Z
Learning: When adding validation in `validate*` functions in `packages/xrpl/src/models/transactions/`, utilize existing helper functions (e.g., `validateOptionalField`, `validateType`, `isNumber`, `isInteger`) for type checking and validation where appropriate.

Applied to files:

  • packages/xrpl/src/models/transactions/vaultCreate.ts
  • packages/xrpl/src/models/transactions/common.ts
📚 Learning: 2024-12-06T18:44:55.095Z
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/models/MPTokenAuthorize.test.ts:60-71
Timestamp: 2024-12-06T18:44:55.095Z
Learning: In the XRPL.js library's TypeScript test file `packages/xrpl/test/models/MPTokenAuthorize.test.ts`, negative test cases for invalid `Account` address format, invalid `Holder` address format, invalid `MPTokenIssuanceID` format, and invalid flag combinations are not necessary.

Applied to files:

  • packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts
  • packages/xrpl/test/models/payment.test.ts
  • packages/xrpl/test/models/MPTokenIssuanceCreate.test.ts
📚 Learning: 2024-12-18T20:54:40.935Z
Learnt from: achowdhry-ripple
PR: XRPLF/xrpl.js#2829
File: packages/xrpl/src/models/transactions/CredentialAccept.ts:36-44
Timestamp: 2024-12-18T20:54:40.935Z
Learning: The validateCredentialType function already checks that CredentialType is a properly hex-encoded string within the allowed length.

Applied to files:

  • packages/xrpl/src/models/transactions/common.ts
🧬 Code graph analysis (7)
packages/xrpl/src/sugar/autofill.ts (1)
packages/xrpl/src/errors.ts (1)
  • ValidationError (156-156)
packages/xrpl/test/testUtils.ts (2)
packages/xrpl/src/errors.ts (1)
  • ValidationError (156-156)
packages/xrpl/src/models/transactions/transaction.ts (1)
  • validate (231-519)
packages/xrpl/src/models/transactions/vaultCreate.ts (1)
packages/xrpl/src/models/transactions/common.ts (4)
  • validateOptionalField (547-573)
  • isHexString (179-181)
  • isXRPLNumber (262-269)
  • isNumber (190-198)
packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts (4)
packages/xrpl/src/models/transactions/common.ts (4)
  • validateOptionalField (547-573)
  • isHexString (179-181)
  • isNumber (190-198)
  • isString (154-156)
packages/xrpl/src/errors.ts (1)
  • ValidationError (156-156)
packages/xrpl/src/models/utils/index.ts (1)
  • isFlagEnabled (28-31)
packages/xrpl/src/models/transactions/index.ts (1)
  • MPTokenIssuanceCreateFlags (59-59)
packages/xrpl/src/models/transactions/payment.ts (1)
packages/xrpl/src/models/transactions/common.ts (9)
  • validateRequiredField (500-532)
  • isAmount (417-423)
  • isAccount (404-409)
  • validateOptionalField (547-573)
  • isNumber (190-198)
  • isHexString (179-181)
  • validateCredentialsList (781-823)
  • MAX_AUTHORIZED_CREDENTIALS (25-25)
  • isDomainID (871-877)
packages/xrpl/src/models/transactions/common.ts (2)
packages/xrpl/src/models/utils/index.ts (1)
  • isHex (61-63)
packages/xrpl/src/models/common/index.ts (4)
  • Currency (21-21)
  • IssuedCurrency (12-15)
  • MPTCurrency (17-19)
  • XRPAmount (23-23)
packages/xrpl/src/models/transactions/vaultDeposit.ts (1)
packages/xrpl/src/models/transactions/common.ts (2)
  • validateRequiredField (500-532)
  • isHexString (179-181)
🪛 ast-grep (0.39.6)
packages/xrpl/test/testUtils.ts

[warning] 84-88: Regular expression constructed from variable input detected. This can lead to Regular Expression Denial of Service (ReDoS) attacks if the variable contains malicious patterns. Use libraries like 'recheck' to validate regex safety or use static patterns.
Context: new RegExp(
// eslint-disable-next-line require-unicode-regexp -- TS complains if it's included
^${errorMessage.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}$,
'u',
)
Note: [CWE-1333] Inefficient Regular Expression Complexity [REFERENCES]
- https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS
- https://cwe.mitre.org/data/definitions/1333.html

(regexp-from-variable)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: integration (20.x)
  • GitHub Check: integration (22.x)
  • GitHub Check: unit (20.x)
  • GitHub Check: integration (24.x)
  • GitHub Check: unit (24.x)
  • GitHub Check: browser (24.x)
  • GitHub Check: unit (22.x)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (17)
packages/xrpl/src/models/transactions/batch.ts (1)

121-125: LGTM! Error message improvement.

The updated error message is more specific and descriptive. Using "expected a valid Record" is more precise than "is not object" since isRecord checks for plain objects with string keys, not just any object type.

packages/xrpl/test/testUtils.ts (1)

78-82: LGTM! Flexible parameter type enhances test capabilities.

Adding support for RegExp in addition to string for the errorMessage parameter is a valuable enhancement that allows test writers to use pattern matching while maintaining backward compatibility.

packages/xrpl/src/sugar/autofill.ts (3)

122-125: Good improvement: using presence check for Destination.

Switching from a truthy check to the in operator is more robust, as it correctly handles cases where Destination exists but has a falsy value.


149-158: Good refactor: explicit validation improves clarity.

The addition of explicit presence checking (line 149) and type validation (line 154) makes the validation logic clearer and more robust. The introduction of the local val variable ensures type safety after validation.


163-163: Good consistency: using presence check for tagField.

This change aligns with the presence check pattern used elsewhere in the function, correctly handling cases where the tag field might have a falsy value like 0.

packages/xrpl/src/models/transactions/index.ts (1)

41-43: Export paths verified—naming is consistent and files exist.

Verification confirms camelCase paths in lines 41-43 correctly reference actual module files (credentialAccept.ts, credentialCreate.ts, credentialDelete.ts). No broken imports or PascalCase remnants found. The naming aligns with other non-acronym transaction exports, and CI passing validates module resolution.

packages/xrpl/src/models/transactions/vaultCreate.ts (1)

148-160: LGTM on metadata warnings path.

Console warning aggregation is clean and mirrors IssuanceCreate.

packages/xrpl/src/models/transactions/payment.ts (1)

194-204: LGTM: Centralized validation and Paths predicate.

Good use of validateRequired/Optional and a clear isPaths type guard.

Also applies to: 286-301

packages/xrpl/test/models/MPTokenIssuanceCreate.test.ts (1)

41-53: Consolidate empty string validation into a single code path to avoid dual error messages.

The current implementation uses validateOptionalField with isHexString (which accepts empty strings since HEX_REGEX matches * zero or more characters), then adds a separate check at line 146-150 to catch empty strings with a distinct error message. This creates two validation paths for one field:

  • Empty string '' passes isHexString, caught by line 146 → "must not be empty string"
  • Non-hex string 'http://xrpl.org' fails isHexString, caught by validateOptionalField"expected a valid hex string"

Consider using the already-imported validateMPTokenMetadata (line 14) as a wrapper validator that handles both hex format and non-emptiness checks, replacing the dual validation logic at lines 142 and 146-150 with a single validateOptionalField call.

packages/xrpl/src/models/transactions/vaultDeposit.ts (1)

40-41: Review comment is incorrect. VaultID validation requires no changes.

VaultID is consistently validated with isHexString across all five vault transaction types, and test data confirms VaultID length is 16 hex characters (8 bytes), not 64. This differs from DomainID (which is 64 chars and has its own isDomainID validator in Payment/OfferCreate). The current validation approach is intentional and consistent with the codebase design.

Likely an incorrect or invalid review comment.

packages/xrpl/src/models/transactions/common.ts (7)

138-181: LGTM: Clean type guard additions

The new type guards isArray, isCurrencyString, and isHexString are well-implemented and follow TypeScript type guard conventions correctly. The isCurrencyString function appropriately handles both standard (3-letter) and non-standard (40-character hex) currency codes as per XRPL specifications.


190-217: LGTM: Empty string edge case properly handled

The updated isNumber function now correctly rejects empty strings with the num.trim() !== '' check on line 194, addressing the concern raised in previous reviews about Number('') evaluating to 0. The isNumberWithBounds factory function is well-structured and the returned function name matches the invalidMessagesMap entry.


316-318: LGTM: XRP amount validation is correct

The isXRPAmount implementation correctly validates that the input is both a string and a valid numeric value. Since isNumber now rejects empty strings (line 194), the concern from previous reviews about empty strings being treated as "0 drops" has been resolved.


500-573: LGTM: Centralized error messaging improves consistency

The additions of the invalidMessage parameter to both validateRequiredField and validateOptionalField, along with the integration of getErrorMessage, provide a consistent and maintainable approach to error message generation across all transaction validators.


674-730: LGTM: validateBaseTransaction properly refactored

The refactored validateBaseTransaction now leverages the new validation helpers consistently:

  • Account correctly validated with isAccount (not just string check)
  • Fee validated as isXRPAmount
  • Hex fields (AccountTxnID, SigningPubKey, TxnSignature) use isHexString
  • Flags accepts both number and object with a clear custom message
  • Memos and Signers have field-specific error messages

The empty SigningPubKey case for multi-signature is correctly handled since isHexString now accepts empty strings.


72-94: LGTM: Memo validation strengthened with isHexString

The isMemo function now correctly uses isHexString for validating MemoData, MemoFormat, and MemoType fields (lines 82-84), ensuring that memo fields are properly hex-encoded as per XRPL specifications. This is an improvement over any previous looser validation.

Based on learnings.


431-439: LGTM: XChainBridge validation improved with explicit type guards

The refactored isXChainBridge now uses explicit type guards (isString for door addresses and isCurrency for currency objects), providing clearer validation and better error messages compared to implicit checks.

Based on learnings.

Comment on lines 141 to 145
validateOptionalField(tx, 'MaximumAmount', isString)
validateOptionalField(tx, 'MPTokenMetadata', isString)
validateOptionalField(tx, 'MPTokenMetadata', isHexString)
validateOptionalField(tx, 'TransferFee', isNumber)
validateOptionalField(tx, 'AssetScale', isNumber)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

AssetScale should be non-negative.

isNumber accepts negative integers; add a non-negative check per doc.

   validateOptionalField(tx, 'AssetScale', isNumber)
+  if (isNumber(tx.AssetScale) && Number(tx.AssetScale) < 0) {
+    throw new ValidationError(
+      'MPTokenIssuanceCreate: AssetScale must be a non-negative integer',
+    )
+  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
validateOptionalField(tx, 'MaximumAmount', isString)
validateOptionalField(tx, 'MPTokenMetadata', isString)
validateOptionalField(tx, 'MPTokenMetadata', isHexString)
validateOptionalField(tx, 'TransferFee', isNumber)
validateOptionalField(tx, 'AssetScale', isNumber)
validateOptionalField(tx, 'MaximumAmount', isString)
validateOptionalField(tx, 'MPTokenMetadata', isHexString)
validateOptionalField(tx, 'TransferFee', isNumber)
validateOptionalField(tx, 'AssetScale', isNumber)
if (isNumber(tx.AssetScale) && Number(tx.AssetScale) < 0) {
throw new ValidationError(
'MPTokenIssuanceCreate: AssetScale must be a non-negative integer',
)
}
🤖 Prompt for AI Agents
In packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts around lines
141 to 145, the AssetScale field is currently validated with isNumber which
permits negative values; update the validation so AssetScale, when present, must
be a non-negative number (e.g., replace the validator with a predicate that
checks isNumber(value) && value >= 0 or use an existing nonNegativeNumber
helper) to enforce the documented constraint.

Comment on lines +175 to 181
if (isNumber(tx.TransferFee)) {
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Not necessary
const flags = (tx.Flags ?? 0) as
| number
| MPTokenIssuanceCreateFlagsInterface
const isTfMPTCanTransfer =
typeof flags === 'number'
? isFlagEnabled(flags, MPTokenIssuanceCreateFlags.tfMPTCanTransfer)
: (flags.tfMPTCanTransfer ?? false)
const flags = (tx.Flags ?? 0) as number | Record<string, unknown>
const isTfMPTCanTransfer = isNumber(flags)
? isFlagEnabled(flags, MPTokenIssuanceCreateFlags.tfMPTCanTransfer)
: flags.tfMPTCanTransfer === true

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

TransferFee presence check ignores 0; enforce presence regardless of value.

Field must not be present without tfMPTCanTransfer.

-    if (tx.TransferFee && !isTfMPTCanTransfer) {
+    if (tx.TransferFee !== undefined && !isTfMPTCanTransfer) {
       throw new ValidationError(
         'MPTokenIssuanceCreate: TransferFee cannot be provided without enabling tfMPTCanTransfer flag',
       )
     }

Also applies to: 188-192


🏁 Script executed:

#!/bin/bash
# Find tests missing the TransferFee=0 case
rg -n "TransferFee\\s*:\\s*0" packages/xrpl/test/models/MPTokenIssuanceCreate.test.ts -C2 || true

Length of output: 0


I need to gather more information by inspecting the actual code and searching more broadly for test coverage. Let me verify the implementation and test cases.


🏁 Script executed:

#!/bin/bash
# View the actual code at lines 175-181 and 188-192
echo "=== Lines 175-181 ==="
sed -n '175,181p' packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts

echo ""
echo "=== Lines 188-192 ==="
sed -n '188,192p' packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts

echo ""
echo "=== Broader search for TransferFee in tests ==="
rg -n "TransferFee" packages/xrpl/test/models/MPTokenIssuanceCreate.test.ts -C2 || echo "No matches found"

Length of output: 2223


Bug confirmed: presence check for TransferFee incorrectly ignores 0 value.

The current validation at line 188 uses if (tx.TransferFee && !isTfMPTCanTransfer), which fails to validate when TransferFee is set to 0 (a falsy value). Since 0 is a valid value within the allowed range (0-50000), it should still require the tfMPTCanTransfer flag to be enabled. The proposed fix to use tx.TransferFee !== undefined is correct and necessary.

Test coverage shows no test case for the edge case of TransferFee: 0 without the required flag, which would currently pass validation incorrectly.

🤖 Prompt for AI Agents
In packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts around lines
175 to 181, the present validation uses a truthy check for tx.TransferFee which
incorrectly ignores a valid value of 0; change the conditional to test for
defined-ness (tx.TransferFee !== undefined) so that 0 still triggers the
requirement for the tfMPTCanTransfer flag, update the surrounding logic to use
the computed isTfMPTCanTransfer value accordingly, and add a unit test covering
the edge case TransferFee: 0 without the flag to ensure it fails validation.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/xrpl/src/models/transactions/common.ts (2)

269-277: LGTM! isXRPAmount correctly validates XRP drop amounts.

The implementation reuses isNumber (which now rejects empty strings), addressing the past review concern about empty string acceptance. The docstring should be updated though—it says "IssuedCurrencyAmount" but validates XRP amounts.

🔎 Fix docstring
 /**
- * Verify the form and type of an IssuedCurrencyAmount at runtime.
+ * Verify the form and type of an XRPAmount (drops) at runtime.
  *
  * @param input - The input to check the form and type of.
- * @returns Whether the IssuedCurrencyAmount is properly formed.
+ * @returns Whether the XRPAmount is properly formed.
  */
 export function isXRPAmount(input: unknown): input is XRPAmount {

827-831: Minor: Weak type guard in isAuthorizeCredentialArray.

The comment acknowledges this is not a rigorous type guard. While acceptable for internal use, consider adding a note that this assumes the array is non-empty and homogeneous, or add a more thorough check if this function is used in contexts where the assumption might not hold.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 014892b and 9de5190.

📒 Files selected for processing (9)
  • packages/xrpl/src/models/common/index.ts
  • packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts
  • packages/xrpl/src/models/transactions/common.ts
  • packages/xrpl/src/models/transactions/index.ts
  • packages/xrpl/src/models/transactions/transaction.ts
  • packages/xrpl/src/models/transactions/vaultCreate.ts
  • packages/xrpl/src/sugar/autofill.ts
  • packages/xrpl/test/models/MPTokenIssuanceCreate.test.ts
  • packages/xrpl/test/models/vaultCreate.test.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • packages/xrpl/src/sugar/autofill.ts
  • packages/xrpl/test/models/MPTokenIssuanceCreate.test.ts
  • packages/xrpl/src/models/transactions/index.ts
  • packages/xrpl/src/models/transactions/vaultCreate.ts
🧰 Additional context used
🧠 Learnings (23)
📓 Common learnings
Learnt from: achowdhry-ripple
Repo: XRPLF/xrpl.js PR: 2661
File: packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts:69-102
Timestamp: 2024-12-05T16:48:12.951Z
Learning: When adding validation in `validate*` functions in `packages/xrpl/src/models/transactions/`, utilize existing helper functions (e.g., `validateOptionalField`, `validateType`, `isNumber`, `isInteger`) for type checking and validation where appropriate.
Learnt from: ckeshava
Repo: XRPLF/xrpl.js PR: 2874
File: packages/xrpl/test/models/permissionedDomainDelete.test.ts:15-20
Timestamp: 2025-01-08T02:11:21.997Z
Learning: In validation test cases for XRPL transactions, using generic JSON input (e.g., `as any`) is preferred over strict typing as it better represents real-world scenarios where the `validate` method needs to handle arbitrary JSON/map/dictionary input from users.
Learnt from: mvadari
Repo: XRPLF/xrpl.js PR: 2895
File: packages/xrpl/test/models/clawback.test.ts:0-0
Timestamp: 2025-02-12T23:28:55.377Z
Learning: The `validate` function in xrpl.js is synchronous and should be tested using `assert.doesNotThrow` rather than async assertions.
Learnt from: ckeshava
Repo: XRPLF/xrpl.js PR: 2873
File: packages/xrpl/src/models/transactions/trustSet.ts:33-36
Timestamp: 2025-01-08T13:08:52.688Z
Learning: For trust-set transactions in XRPL, validation rules for flags should be implemented comprehensively rather than cherry-picking specific rules, as there are many interdependent validation rules associated with these flags.
Learnt from: ckeshava
Repo: XRPLF/xrpl.js PR: 2874
File: packages/xrpl/test/integration/transactions/permissionedDomain.test.ts:25-80
Timestamp: 2025-01-08T02:12:28.489Z
Learning: The rippled C++ implementation (PR #5161) includes comprehensive test coverage for PermissionedDomain (XLS-80d) error cases. The JS SDK tests focus on the happy path since the error cases are already validated at the rippled level, following the principle of not duplicating complex validation testing across SDK implementations.
Learnt from: ckeshava
Repo: XRPLF/xrpl.js PR: 3032
File: packages/xrpl/src/models/transactions/common.ts:689-698
Timestamp: 2025-07-10T22:04:59.994Z
Learning: In the XRPL.js library, the validateDomainID function in `packages/xrpl/src/models/transactions/common.ts` should only validate the length (64 characters) of domain IDs, not hex encoding. The rippled C++ implementation does not enforce any regex check on domain ID values, so additional hex validation is not required in the JS implementation.
Learnt from: ckeshava
Repo: XRPLF/xrpl.js PR: 3032
File: packages/xrpl/src/models/transactions/common.ts:689-698
Timestamp: 2025-07-11T21:22:07.809Z
Learning: Domain ID validation in XRPL.js is handled at the serialization/deserialization layer through Hash types in the ripple-binary-codec package, not at the transaction validation layer. The validateDomainID function only needs to validate length (64 characters) as hex validation occurs when Hash types are constructed during serialization.
Learnt from: shawnxie999
Repo: XRPLF/xrpl.js PR: 2661
File: packages/xrpl/test/models/MPTokenAuthorize.test.ts:60-71
Timestamp: 2024-12-06T18:44:55.095Z
Learning: In the XRPL.js library's TypeScript test file `packages/xrpl/test/models/MPTokenAuthorize.test.ts`, negative test cases for invalid `Account` address format, invalid `Holder` address format, invalid `MPTokenIssuanceID` format, and invalid flag combinations are not necessary.
Learnt from: ckeshava
Repo: XRPLF/xrpl.js PR: 3081
File: packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts:298-298
Timestamp: 2025-10-30T12:09:55.784Z
Learning: In XRPL's MPTokenIssuanceCreate transaction validation, MaximumAmount must be greater than 0 (not greater than or equal to). The rippled C++ implementation at MPTokenIssuanceCreate.cpp explicitly rejects MaximumAmount == 0 with temMALFORMED, so the JavaScript validation should use `<= 0` to match this behavior.
Learnt from: shawnxie999
Repo: XRPLF/xrpl.js PR: 2661
File: packages/xrpl/test/integration/transactions/mptokenAuthorize.test.ts:29-118
Timestamp: 2024-12-06T19:25:15.376Z
Learning: In the XRPLF/xrpl.js TypeScript client library, when writing tests (e.g., in `packages/xrpl/test/integration/transactions/`), we generally do not need to test rippled server behaviors, because those behaviors are covered by rippled's own integration and unit tests.
📚 Learning: 2025-06-26T17:25:36.429Z
Learnt from: ckeshava
Repo: XRPLF/xrpl.js PR: 3027
File: packages/xrpl/src/models/ledger/MPTokenIssuance.ts:13-16
Timestamp: 2025-06-26T17:25:36.429Z
Learning: In the XRPL ecosystem, type choices for amount fields (like `number` vs `string`) in ledger objects such as `LockedAmount` vs `OutstandingAmount` in `MPTokenIssuance` are deliberate design decisions made across multiple products and cannot be changed unilaterally by individual contributors.

Applied to files:

  • packages/xrpl/src/models/common/index.ts
  • packages/xrpl/src/models/transactions/common.ts
📚 Learning: 2025-10-30T12:09:55.784Z
Learnt from: ckeshava
Repo: XRPLF/xrpl.js PR: 3081
File: packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts:298-298
Timestamp: 2025-10-30T12:09:55.784Z
Learning: In XRPL's MPTokenIssuanceCreate transaction validation, MaximumAmount must be greater than 0 (not greater than or equal to). The rippled C++ implementation at MPTokenIssuanceCreate.cpp explicitly rejects MaximumAmount == 0 with temMALFORMED, so the JavaScript validation should use `<= 0` to match this behavior.

Applied to files:

  • packages/xrpl/src/models/common/index.ts
  • packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts
  • packages/xrpl/src/models/transactions/common.ts
📚 Learning: 2024-12-06T19:25:15.376Z
Learnt from: shawnxie999
Repo: XRPLF/xrpl.js PR: 2661
File: packages/xrpl/test/integration/transactions/mptokenAuthorize.test.ts:29-118
Timestamp: 2024-12-06T19:25:15.376Z
Learning: In the XRPLF/xrpl.js TypeScript client library, when writing tests (e.g., in `packages/xrpl/test/integration/transactions/`), we generally do not need to test rippled server behaviors, because those behaviors are covered by rippled's own integration and unit tests.

Applied to files:

  • packages/xrpl/src/models/common/index.ts
  • packages/xrpl/src/models/transactions/transaction.ts
  • packages/xrpl/test/models/vaultCreate.test.ts
  • packages/xrpl/src/models/transactions/common.ts
📚 Learning: 2025-10-28T14:16:24.585Z
Learnt from: Patel-Raj11
Repo: XRPLF/xrpl.js PR: 3117
File: packages/xrpl/src/models/transactions/common.ts:1133-1180
Timestamp: 2025-10-28T14:16:24.585Z
Learning: The MPTokenMetadata TypeScript interface in xrpl.js reflects the XLS-89 standard (long-form fields only) to provide correct type hints for IDEs and TypeScript users, even though JavaScript users may provide non-standard structures with compact fields or both forms present. This design provides proper tooling support while maintaining runtime flexibility.

Applied to files:

  • packages/xrpl/src/models/common/index.ts
  • packages/xrpl/test/models/vaultCreate.test.ts
  • packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts
  • packages/xrpl/src/models/transactions/common.ts
📚 Learning: 2025-01-08T02:08:00.476Z
Learnt from: ckeshava
Repo: XRPLF/xrpl.js PR: 2874
File: packages/xrpl/src/models/ledger/PermissionedDomain.ts:3-8
Timestamp: 2025-01-08T02:08:00.476Z
Learning: In xrpl.js, the Credential interface must maintain a nested structure with a `Credential` property containing `Issuer` and `CredentialType` fields to mirror the structure defined in the rippled codebase.

Applied to files:

  • packages/xrpl/src/models/common/index.ts
  • packages/xrpl/src/models/transactions/transaction.ts
  • packages/xrpl/src/models/transactions/common.ts
📚 Learning: 2024-12-12T01:12:01.868Z
Learnt from: mvadari
Repo: XRPLF/xrpl.js PR: 2829
File: packages/xrpl/src/models/methods/ledgerEntry.ts:74-85
Timestamp: 2024-12-12T01:12:01.868Z
Learning: In the XRPL.js library, request parameters use camelCase (e.g., `credentialType`), while transaction model fields follow the XRP Ledger protocol's PascalCase convention (e.g., `CredentialType`).

Applied to files:

  • packages/xrpl/src/models/transactions/transaction.ts
  • packages/xrpl/src/models/transactions/common.ts
📚 Learning: 2024-10-02T15:47:02.491Z
Learnt from: mvadari
Repo: XRPLF/xrpl.js PR: 2690
File: packages/xrpl/tools/generateModels.js:52-52
Timestamp: 2024-10-02T15:47:02.491Z
Learning: In `generateModels.js`, the regex used to match `SubmittableTransaction` in `transaction.ts` is expected to always succeed because the pattern is present in the source code. If it fails, the code needs to be updated.

Applied to files:

  • packages/xrpl/src/models/transactions/transaction.ts
  • packages/xrpl/test/models/vaultCreate.test.ts
  • packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts
📚 Learning: 2024-12-06T19:27:11.147Z
Learnt from: shawnxie999
Repo: XRPLF/xrpl.js PR: 2661
File: packages/xrpl/test/integration/transactions/clawback.test.ts:165-178
Timestamp: 2024-12-06T19:27:11.147Z
Learning: In the integration tests for `clawback.test.ts`, it's acceptable to use `ts-expect-error` to bypass type checking when verifying ledger entries, and no additional type safety improvements are needed.

Applied to files:

  • packages/xrpl/test/models/vaultCreate.test.ts
  • packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts
  • packages/xrpl/src/models/transactions/common.ts
📚 Learning: 2024-12-06T18:44:55.095Z
Learnt from: shawnxie999
Repo: XRPLF/xrpl.js PR: 2661
File: packages/xrpl/test/models/MPTokenAuthorize.test.ts:60-71
Timestamp: 2024-12-06T18:44:55.095Z
Learning: In the XRPL.js library's TypeScript test file `packages/xrpl/test/models/MPTokenAuthorize.test.ts`, negative test cases for invalid `Account` address format, invalid `Holder` address format, invalid `MPTokenIssuanceID` format, and invalid flag combinations are not necessary.

Applied to files:

  • packages/xrpl/test/models/vaultCreate.test.ts
  • packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts
  • packages/xrpl/src/models/transactions/common.ts
📚 Learning: 2025-04-16T15:22:45.633Z
Learnt from: mvadari
Repo: XRPLF/xrpl.js PR: 2801
File: packages/xrpl/test/models/Batch.test.ts:0-0
Timestamp: 2025-04-16T15:22:45.633Z
Learning: Using `as any` type assertions is acceptable in test files for the XRPL.js project, as strict typing is not required for test code.

Applied to files:

  • packages/xrpl/test/models/vaultCreate.test.ts
  • packages/xrpl/src/models/transactions/common.ts
📚 Learning: 2025-02-12T23:30:40.622Z
Learnt from: mvadari
Repo: XRPLF/xrpl.js PR: 2895
File: packages/xrpl/test/models/DIDDelete.test.ts:28-31
Timestamp: 2025-02-12T23:30:40.622Z
Learning: In JavaScript/TypeScript transaction validation tests, object key validation can be performed using:
1. Object.keys() comparison with expected set
2. TypeScript interfaces with strict object literal checks
3. Object sanitization by filtering to allowed keys only

Applied to files:

  • packages/xrpl/test/models/vaultCreate.test.ts
  • packages/xrpl/src/models/transactions/common.ts
📚 Learning: 2025-02-12T23:28:55.377Z
Learnt from: mvadari
Repo: XRPLF/xrpl.js PR: 2895
File: packages/xrpl/test/models/clawback.test.ts:0-0
Timestamp: 2025-02-12T23:28:55.377Z
Learning: The `validate` function in xrpl.js is synchronous and should be tested using `assert.doesNotThrow` rather than async assertions.

Applied to files:

  • packages/xrpl/test/models/vaultCreate.test.ts
  • packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts
📚 Learning: 2025-10-28T14:16:24.585Z
Learnt from: Patel-Raj11
Repo: XRPLF/xrpl.js PR: 3117
File: packages/xrpl/src/models/transactions/common.ts:1133-1180
Timestamp: 2025-10-28T14:16:24.585Z
Learning: In xrpl.js MPTokenMetadata handling: encodeMPTokenMetadata and decodeMPTokenMetadata are designed to preserve the original structure of the input, only converting between compact and long forms when a single form is present (not both). If both compact (e.g., 'us') and long (e.g., 'uris') forms exist in the input, both are preserved in the output. This is intentional to avoid modifying the user's data. Validation (validateMPTokenMetadata) separately checks and reports XLS-89 compliance.

Applied to files:

  • packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts
📚 Learning: 2025-09-16T05:00:20.420Z
Learnt from: ckeshava
Repo: XRPLF/xrpl.js PR: 3081
File: packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts:57-64
Timestamp: 2025-09-16T05:00:20.420Z
Learning: In XRPL's MPTokenIssuanceCreate flags, the tfMPTCanMutate* flags intentionally use the same bit values as their corresponding base flags (e.g., tfMPTCanMutateCanLock = 0x00000002 matches tfMPTCanLock = 0x00000002) because they operate in different contexts - base flags go in the Flags field while mutable flags go in the MutableFlags field. This design avoids ambiguity since the flags are applied to separate bit fields.

Applied to files:

  • packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts
📚 Learning: 2025-07-10T22:04:59.994Z
Learnt from: ckeshava
Repo: XRPLF/xrpl.js PR: 3032
File: packages/xrpl/src/models/transactions/common.ts:689-698
Timestamp: 2025-07-10T22:04:59.994Z
Learning: In the XRPL.js library, the validateDomainID function in `packages/xrpl/src/models/transactions/common.ts` should only validate the length (64 characters) of domain IDs, not hex encoding. The rippled C++ implementation does not enforce any regex check on domain ID values, so additional hex validation is not required in the JS implementation.

Applied to files:

  • packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts
  • packages/xrpl/src/models/transactions/common.ts
📚 Learning: 2024-12-05T16:48:12.951Z
Learnt from: achowdhry-ripple
Repo: XRPLF/xrpl.js PR: 2661
File: packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts:69-102
Timestamp: 2024-12-05T16:48:12.951Z
Learning: When adding validation in `validate*` functions in `packages/xrpl/src/models/transactions/`, utilize existing helper functions (e.g., `validateOptionalField`, `validateType`, `isNumber`, `isInteger`) for type checking and validation where appropriate.

Applied to files:

  • packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts
  • packages/xrpl/src/models/transactions/common.ts
📚 Learning: 2024-12-18T20:54:40.935Z
Learnt from: achowdhry-ripple
Repo: XRPLF/xrpl.js PR: 2829
File: packages/xrpl/src/models/transactions/CredentialAccept.ts:36-44
Timestamp: 2024-12-18T20:54:40.935Z
Learning: The validateCredentialType function already checks that CredentialType is a properly hex-encoded string within the allowed length.

Applied to files:

  • packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts
  • packages/xrpl/src/models/transactions/common.ts
📚 Learning: 2024-10-30T01:05:33.583Z
Learnt from: ckeshava
Repo: XRPLF/xrpl.js PR: 2812
File: packages/xrpl/test/integration/transactions/payment.test.ts:41-43
Timestamp: 2024-10-30T01:05:33.583Z
Learning: In tests involving fee calculations for XRPL, avoid using default fee amounts. If unable to retrieve fee values from the latest validated ledger, throw an error instead of defaulting to a specific amount.

Applied to files:

  • packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts
📚 Learning: 2024-10-08T16:29:11.194Z
Learnt from: ckeshava
Repo: XRPLF/xrpl.js PR: 2795
File: packages/xrpl/src/models/transactions/common.ts:84-84
Timestamp: 2024-10-08T16:29:11.194Z
Learning: When dealing with `bigint` values, avoid converting them to `number` to prevent loss of precision.

Applied to files:

  • packages/xrpl/src/models/transactions/common.ts
📚 Learning: 2025-07-11T21:22:07.809Z
Learnt from: ckeshava
Repo: XRPLF/xrpl.js PR: 3032
File: packages/xrpl/src/models/transactions/common.ts:689-698
Timestamp: 2025-07-11T21:22:07.809Z
Learning: Domain ID validation in XRPL.js is handled at the serialization/deserialization layer through Hash types in the ripple-binary-codec package, not at the transaction validation layer. The validateDomainID function only needs to validate length (64 characters) as hex validation occurs when Hash types are constructed during serialization.

Applied to files:

  • packages/xrpl/src/models/transactions/common.ts
📚 Learning: 2025-01-17T09:27:33.335Z
Learnt from: ckeshava
Repo: XRPLF/xrpl.js PR: 2874
File: packages/xrpl/src/models/transactions/permissionedDomainSet.ts:32-33
Timestamp: 2025-01-17T09:27:33.335Z
Learning: Use `Array.isArray()` instead of `instanceof Array` for reliable array type checking in JavaScript, as `instanceof Array` fails for cross-realm arrays (e.g., from iframes) and arrays from different JavaScript contexts.

Applied to files:

  • packages/xrpl/src/models/transactions/common.ts
📚 Learning: 2025-01-14T20:47:34.164Z
Learnt from: mvadari
Repo: XRPLF/xrpl.js PR: 2874
File: packages/xrpl/src/models/transactions/permissionedDomainSet.ts:14-14
Timestamp: 2025-01-14T20:47:34.164Z
Learning: The PermissionedDomain's AcceptedCredentials array has a maximum length of 10 as per XLS-80d specification, which is different from the credentials feature limit. These limits should not be aligned as they serve different purposes.

Applied to files:

  • packages/xrpl/src/models/transactions/common.ts
🧬 Code graph analysis (1)
packages/xrpl/src/models/transactions/common.ts (2)
packages/xrpl/src/models/utils/index.ts (1)
  • isHex (61-63)
packages/xrpl/src/models/common/index.ts (4)
  • Currency (21-21)
  • IssuedCurrency (12-15)
  • MPTCurrency (17-19)
  • XRPAmount (23-23)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: unit (20.x)
  • GitHub Check: integration (24.x)
  • GitHub Check: integration (22.x)
  • GitHub Check: integration (20.x)
  • GitHub Check: unit (24.x)
  • GitHub Check: browser (24.x)
  • GitHub Check: unit (22.x)
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (14)
packages/xrpl/src/models/transactions/transaction.ts (1)

26-28: LGTM! Naming consistency improved.

The import path changes from PascalCase to camelCase align these Credential modules with the existing convention used by most other transaction types in this file (e.g., accountDelete, accountSet, checkCancel). The public API remains unchanged since the named exports retain their PascalCase identifiers.

packages/xrpl/src/models/common/index.ts (1)

23-24: LGTM! Semantic type alias improves clarity.

The introduction of XRPAmount as a type alias for string and its use in the Amount union type improves code readability and self-documentation without introducing breaking changes. This aligns well with the broader refactor to provide more explicit type information.

Also applies to: 35-35

packages/xrpl/test/models/vaultCreate.test.ts (3)

22-22: LGTM! Using any type in tests is appropriate.

Based on learnings, using as any type assertions is acceptable in test files for the XRPL.js project. This approach better represents real-world scenarios where the validate method handles arbitrary JSON input from users.


56-70: LGTM! Updated error messages align with centralized validation.

The updated assertions correctly reflect the new, more descriptive error message format from the refactored validation helpers. The messages now include field names and expected types (e.g., "expected a valid Currency", "expected a valid hex string"), which improves debuggability.


93-99: LGTM! Consistent error message format for WithdrawalPolicy.

The test correctly expects the new standardized error message format for invalid number fields.

packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts (2)

143-151: LGTM! Enhanced validation for MPTokenMetadata.

The change from isString to isHexString ensures the field is validated as a hex string rather than just any string. The explicit empty string check (lines 147-151) correctly rejects empty metadata before the length validation at lines 153-161.


176-181: Widened flags type is reasonable for runtime flexibility.

The change from MPTokenIssuanceCreateFlagsInterface to Record<string, unknown> for the flags type acknowledges that at runtime, the flags object may not conform exactly to the expected interface. The logic correctly handles both numeric flags and object-based flags.

packages/xrpl/src/models/transactions/common.ts (7)

97-105: LGTM! New isArray type guard is well-implemented.

The guard correctly uses Array.isArray() as per learnings (preferred over instanceof Array for cross-realm safety) and includes a null check.


117-130: LGTM! isCurrencyString provides clear validation for currency codes.

The guard correctly validates both standard 3-letter currency codes (e.g., "USD") and non-standard 40-character hex currency codes. This centralizes currency string validation logic.


138-140: LGTM! isHexString consolidates type and format check.

This guard addresses the earlier concern about isHex assuming the input is a string. It now checks both typeof str === 'string' and isHex(str).


149-157: LGTM! isNumber now correctly rejects empty strings.

The updated implementation addresses the past review concern about Number('') evaluating to 0. The check num.trim() !== '' prevents empty or whitespace-only strings from being accepted as valid numbers.


168-176: LGTM! isNumberWithBounds is a useful helper for bounded numeric validation.

The higher-order function pattern allows reusable bounded checks (e.g., for TradingFee, TickSize). The returned function has an explicit name (isNumberWithBoundsInternal) which is mapped in invalidMessagesMap.


236-267: LGTM! Currency type guards are well-structured.

The decomposition into isXRPCurrency, isIssuedCurrency, and isMPTCurrency with isCurrency as their composition provides clear, reusable validation. Each guard correctly validates the expected object shape and field count.


682-723: LGTM! validateBaseTransaction uses new centralized validators.

The updated validation correctly uses isAccount, isXRPAmount, isHexString, and other new guards. The custom inline validator for Flags (line 698) handles both numeric and object forms. Error messages for Memos and Signers are appropriately simplified since these have complex validation logic.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/xrpl/test/models/vaultCreate.test.ts (1)

193-196: ⚠️ Potential issue | 🔴 Critical

Both the unused @ts-expect-error directive and the incorrect error message expectation need to be fixed.

Since tx is typed as any on line 22, the @ts-expect-error on line 194 is unnecessary and should be removed.

More critically, the expected error message is incorrect. When Scale is set to 'invalid' for an IOU asset, the validation throws 'VaultCreate: Scale must be a number between 0 and 18 inclusive for IOU assets', not 'VaultCreate: invalid field Scale'. This test will fail with the current expectation.

Fix required
-      // `@ts-expect-error` for test
       tx.Scale = 'invalid'
-      assertInvalid(tx, 'VaultCreate: invalid field Scale')
+      assertInvalid(tx, 'VaultCreate: Scale must be a number between 0 and 18 inclusive for IOU assets')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make validateRequiredField & validateOptionalField errors more specific

3 participants